Error Binding DropDownList on EditItem Command of DataGrid Control

  • Thread starter Shane O. Pinnell
  • Start date
S

Shane O. Pinnell

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>&nbsp;
<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_SelectedIndex(Int32 value)
System.Web.UI.WebControls.DropDownList.set_SelectedIndex(Int32 value)
System.Web.UI.WebControls.ListControl.OnDataBinding(EventArgs e)
System.Web.UI.Control.DataBind()
System.Web.UI.Control.DataBind()
System.Web.UI.Control.DataBind()
System.Web.UI.WebControls.DataGrid.CreateItem(Int32 itemIndex, Int32 dataSourceIndex, ListItemType itemType, Boolean dataBind, Object dataItem, DataGridColumn[] columns, TableRowCollection rows, PagedDataSource pagedDataSource)
System.Web.UI.WebControls.DataGrid.CreateControlHierarchy(Boolean useDataSource)
System.Web.UI.WebControls.BaseDataList.OnDataBinding(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(DataGridCommandEventArgse)
System.Web.UI.WebControls.DataGrid.OnBubbleEvent(Object source, EventArgs e)
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)
System.Web.UI.WebControls.DataGridItem.OnBubbleEvent(Object source, EventArgs e)
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)
System.Web.UI.WebControls.Button.OnCommand(CommandEventArgs e)
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection 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!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top