Error Binding DropDownList on EditItem Command of DataGrid Control

Discussion in 'ASP .Net' started by Shane O. Pinnell, Jul 9, 2003.

  1. 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!
     
    Shane O. Pinnell, Jul 9, 2003
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Lars Netzel
    Replies:
    1
    Views:
    455
    Lars Netzel
    Jul 30, 2004
  2. =?Utf-8?B?eXVjaGFuZw==?=
    Replies:
    0
    Views:
    532
    =?Utf-8?B?eXVjaGFuZw==?=
    Apr 15, 2006
  3. Shane O. Pinnell

    Error Binding DropDownList on EditItem Command of DataGrid Control

    Shane O. Pinnell, Jul 9, 2003, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    184
    Shane O. Pinnell
    Jul 9, 2003
  4. rohan_p

    Finding edititem control names in datagrid at runtime

    rohan_p, Oct 15, 2004, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    142
    rohan_p
    Oct 18, 2004
  5. James Cooke
    Replies:
    0
    Views:
    237
    James Cooke
    Sep 11, 2008
Loading...

Share This Page