Hi all, sorry if this is the wrong forum to post this in. Please tell me what forum to post in if this is the wrong forum. Thanks.
I have a very simple drop down list:
1 <Bindable(BindableSupport.Yes, BindingDirection.TwoWay), _
2 ToolboxData("<{0}:DDLPlantFamilies runat=server></{0}:DDLPlantFamilies>")> _
3 Public Class DDLPlantFamilies
4 Inherits WebControl
5 Implements INamingContainer
6
7 Public Sub New()
8 MyBase.New()
9 End Sub
10
11 <Bindable(BindableSupport.Yes, BindingDirection.TwoWay)> _
12 Public Property SelectedValue()
13 Get
14 Return DirectCast(Me.FindControl("ddl"), DropDownList).SelectedValue
15 End Get
16 Set(ByVal value)
17 DirectCast(Me.FindControl("ddl"), DropDownList).SelectedValue = value
18 End Set
19 End Property
20
21 Protected Overrides Sub Render(ByVal writer As System.Web.UI.HtmlTextWriter)
22 MyBase.Render(writer)
23 End Sub
24
25 Protected Overrides Sub CreateChildControls()
26 Dim ddl As New DropDownList
27 Me.Controls.Add(ddl)
28
29 If Not Me.Page.IsPostBack Then
30 Dim listSource As New Bobs.DataObjects.AutoGen._bgd_PlantFamilies
31
32 Dim rdr As SqlClient.SqlDataReader
33 rdr = listSource.LoadAllActiveDDLFromSqlReader
34
35 With listSource
36 ddl.ID = "ddl"
37 ddl.DataSource = rdr
38 ddl.DataValueField = listSource.ColumnNames.PlantFamilyID
39 ddl.DataTextField = listSource.ColumnNames.ScientificFamilyName
40 ddl.DataBind()
41 End With
42 End If
43 End Sub
44 End Class
45
When I try to bind to the drop down list from a GridView row, I get the exception that follows. The list is being loaded fine, and works fine. I only get this error when I'm trying to bind to it from inside a binding context such as a GridView row. Please help. I really appreciate it.
-Andy
The Exception I'm getting:
System.InvalidOperationException was caught
Message="Invalid attempt to FieldCount when reader is closed."
Source="System.Data"
StackTrace:
at System.Data.SqlClient.SqlDataReader.get_FieldCount()
at System.Data.Common.DbEnumerator.BuildSchemaInfo()
at System.Data.Common.DbEnumerator.MoveNext()
at System.Web.UI.WebControls.ListControl.PerformDataBinding(IEnumerable dataSource)
at System.Web.UI.WebControls.ListControl.OnDataBinding(EventArgs e)
at System.Web.UI.WebControls.ListControl.PerformSelect()
at System.Web.UI.WebControls.BaseDataBoundControl.DataBind()
at System.Web.UI.Control.DataBindChildren()
at System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding)
at System.Web.UI.Control.DataBind()
at System.Web.UI.Control.DataBindChildren()
at System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding)
at System.Web.UI.Control.DataBind()
at System.Web.UI.Control.DataBindChildren()
at System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding)
at System.Web.UI.Control.DataBind()
at System.Web.UI.WebControls.GridView.CreateRow(Int32 rowIndex, Int32 dataSourceIndex, DataControlRowType rowType, DataControlRowState rowState, Boolean dataBind, Object dataItem, DataControlField[] fields, TableRowCollection rows, PagedDataSource pagedDataSource)
at System.Web.UI.WebControls.GridView.CreateChildControls(IEnumerable dataSource, Boolean dataBinding)
at System.Web.UI.WebControls.CompositeDataBoundControl.PerformDataBinding(IEnumerable data)
at System.Web.UI.WebControls.GridView.PerformDataBinding(IEnumerable data)
at System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewSelectCallback(IEnumerable data)
at System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback)
at System.Web.UI.WebControls.DataBoundControl.PerformSelect()
at System.Web.UI.WebControls.BaseDataBoundControl.DataBind()
at System.Web.UI.WebControls.GridView.DataBind()
at System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound()
at System.Web.UI.WebControls.CompositeDataBoundControl.CreateChildControls()
at System.Web.UI.Control.EnsureChildControls()
at System.Web.UI.WebControls.CompositeDataBoundControl.get_Controls()
at Utils.SetAllDeleteButtonConfirmationScripts(Control parent) in C:\Documents and Settings\Andy\My Documents\Visual Studio 2005\WebSites\BobsGreenhouseDelights\BobsWeb\App_Code\Utilities\Utilities.vb:line 98