I am sure this has come up before, but I haven't been able to find an answer as of yet. That said, any help is definitely appreciated!
I have a datagrid populated from a dataset. I have a TemplateColumn with a DropDownList (DDL) in the FooterItemTemplate that is populated in the Page_Load event using a Sub Routine as the DataSource of the DDL. The FooterItemTemplate's DDL populates as expected when the DataGrid's DataBind method is called.
<asp:datagrid DataSource="<%# dataset_items %>" >
<Columns>
<asp:TemplateColumn>
<ItemTemplate>
<asp:Button id="Button_Edit" runat="server" Text="Edit" CausesValidation="false" CommandName="Edit"></asp:Button>
</ItemTemplate>
<FooterTemplate>
<asp:Button id="Button_Add" runat="server" Text="Add"></asp:Button>
</FooterTemplate>
<EditItemTemplate>
<asp:Button id="Button_Update" runat="server" Text="Update" CommandName="Update"></asp:Button>
<asp:Button id="Button_Cancel" runat="server" Text="Cancel" CausesValidation="false" CommandName="Cancel"></asp:Button>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Type">
<ItemTemplate>
<asp:Label id=Label_Type runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.type_name", "{0}") %>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:DropDownList id=List_Add_Type runat="server" DataSource="<%# GetTypes() %>"></asp:DropDownList>
</FooterTemplate>
<EditItemTemplate>
<asp:DropDownList id=List_Edit_Type runat="server" DataSource="<%# GetTypes() %>" SelectedIndex='<%# DataBinder.Eval(Container, "DataItem.item_typeID") %>'></asp:DropDownList>
</EditItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid>
My problem is that when I try to populate the EditItemTemplate's DDL from the same dataset that is used to populate the FooterItemTemplate's DDL I get the following error:
Stack Trace:
[ArgumentOutOfRangeException: Specified argument was out of the range of valid values.
Parameter name: value]
System.Web.UI.WebControls.ListControl.set_Selected Index(Int32 value)
System.Web.UI.WebControls.DropDownList.set_Selecte dIndex(Int32 value)
System.Web.UI.WebControls.ListControl.OnDataBindin g(EventArgs e)
System.Web.UI.Control.DataBind()
System.Web.UI.Control.DataBind()
System.Web.UI.Control.DataBind()
System.Web.UI.WebControls.DataGrid.CreateItem(Int3 2 itemIndex, Int32 dataSourceIndex, ListItemType itemType, Boolean dataBind, Object dataItem, DataGridColumn[] columns, TableRowCollection rows, PagedDataSource pagedDataSource)
System.Web.UI.WebControls.DataGrid.CreateControlHi erarchy(Boolean useDataSource)
System.Web.UI.WebControls.BaseDataList.OnDataBindi ng(EventArgs e)
System.Web.UI.WebControls.BaseDataList.DataBind()
Alumawood.diy_items.MyDataGrid_Edit(Object sender, DataGridCommandEventArgs e) in C:\Inetpub\Celerity-Designs\Alumawood\admin\diy_items.aspx.vb:125
System.Web.UI.WebControls.DataGrid.OnEditCommand(D ataGridCommandEventArgse)
System.Web.UI.WebControls.DataGrid.OnBubbleEvent(O bject source, EventArgs e)
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)
System.Web.UI.WebControls.DataGridItem.OnBubbleEve nt(Object source, EventArgs e)
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)
System.Web.UI.WebControls.Button.OnCommand(Command EventArgs e)
System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler sourceControl, String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData)
System.Web.UI.Page.ProcessRequestMain()
------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:1.1.4322.573; ASP.NET Version:1.1.4322.573
I have found some information regarding the binding context, but I wasn't able to figure out what I needed to do!
Thanks Again!