473,325 Members | 2,792 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

Error Binding DropDownList on EditItem Command of DataGrid Control

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_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!
Nov 17 '05 #1
0 4772

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Harold | last post by:
Hi all, having a little difficulty binding up a dropdownlist control in a datagrid column. I know I must be missing something Here are 2 methods. One is the DataGrid's ItemDataBound event to catch...
3
by: mg | last post by:
I have a DataGrid (WebForm - C#) that has a template column that contains a dropdownlist named "DdlTest" In DataGrid1_UpdateCommand, the lin DropDownList ddlTest = (DropDownList)...
2
by: Dave | last post by:
Hi, I'm building a maintenance form for a table and some of the fields are textboxes (i.e name) and some should be dropdowns (i.e country of origin) When a user clicks 'Edit' in the...
3
by: Tim::.. | last post by:
Can someone please tell me how I go about preselecting an item in a drop drown list when I click the Edit Command in a datagrid? I have tried the following but it doesn't work for me! I would...
2
by: jason | last post by:
Pardon my ignorance on this. The below code works, except, when I edit a record and update the two drop downs take the first entry in the dropdownlist if not selected. I'd also like the dropdown to...
2
by: Jeff User | last post by:
Hi C# .NET1.1 I have read Visual Studio help and several articles on the web. Obviously this is a common topic. However, I see this code over and over yet I am stuck with the FindControl method...
2
by: Frank | last post by:
Hello, I am developing with VS.Net 2003 on the asp 1.1 platform. I am a few days new to using a datagrid. I found a nice tutorial and had no problems using an editable datagrid with textboxes...
6
by: p.mc | last post by:
Hi all, I'm having major problems with a userControl which contains a datagrid. My problem concerns data binding. The Page_Load() procedure calls the DataBind procedure to bind the datagrid...
2
by: steven | last post by:
i've got a dropDownList that I'm trying to populate from my code behind as follows: uxVehicleColourEdit.DataSource = oDsLookups.Tables; if the dropDown is placed inside a datagrid, i get...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.