Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Datagrid Control > Error Binding DropDownList on EditItem Command of DataGrid Control

Thread Tools

Error Binding DropDownList on EditItem Command of DataGrid Control

Shane O. Pinnell
Posts: n/a
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 %>" >
<asp:Button id="Button_Edit" runat="server" Text="Edit" CausesValidation="false" CommandName="Edit"></asp:Button>
<asp:Button id="Button_Add" runat="server" Text="Add"></asp:Button>
<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>
<asp:TemplateColumn HeaderText="Type">
<asp:Label id=Label_Type runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.type_name", "{0}") %>'></asp:Label>
<aspropDownList id=List_Add_Type runat="server" DataSource="<%# GetTypes() %>"></aspropDownList>
<aspropDownList id=List_Edit_Type runat="server" DataSource="<%# GetTypes() %>" SelectedIndex='<%# DataBinder.Eval(Container, "DataItem.item_typeID") %>'></aspropDownList>

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.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)
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)


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!
Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Bug: Listview edititem: First item in list has a null edititem James Cooke ASP .Net Web Controls 0 09-11-2008 07:25 PM
How to DataBind droplist control in FormView Control EditItem mode =?Utf-8?B?eXVjaGFuZw==?= ASP .Net 0 04-15-2006 01:35 AM
Finding edititem control names in datagrid at runtime rohan_p ASP .Net Web Controls 1 10-18-2004 03:01 AM
Problem with DropDown in EditItem of Datagrid! Lars Netzel ASP .Net 1 07-30-2004 09:11 AM
Error Binding DropDownList on EditItem Command of DataGrid Control Shane O. Pinnell ASP .Net 0 07-09-2003 12:24 AM