473,699 Members | 3,360 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 FooterItemTempl ate that is populated in the Page_Load event using a Sub Routine as the DataSource of the DDL. The FooterItemTempl ate's DDL populates as expected when the DataGrid's DataBind method is called.

<asp:datagrid DataSource="<%# dataset_items %>" >
<asp:TemplateCo lumn>
<ItemTemplate >
<asp:Button id="Button_Edit " runat="server" Text="Edit" CausesValidatio n="false" CommandName="Ed it"></asp:Button>
<FooterTemplate >
<asp:Button id="Button_Add " runat="server" Text="Add"></asp:Button>
<EditItemTempla te>
<asp:Button id="Button_Upda te" runat="server" Text="Update" CommandName="Up date"></asp:Button>&nbs p;
<asp:Button id="Button_Canc el" runat="server" Text="Cancel" CausesValidatio n="false" CommandName="Ca ncel"></asp:Button>
</EditItemTemplat e>
</asp:TemplateCol umn>
<asp:TemplateCo lumn HeaderText="Typ e">
<ItemTemplate >
<asp:Label id=Label_Type runat="server" Text='<%# DataBinder.Eval (Container, "DataItem.type_ name", "{0}") %>'></asp:Label>
<FooterTemplate >
<asp:DropDownLi st id=List_Add_Typ e runat="server" DataSource="<%# GetTypes() %>"></asp:DropDownLis t>
<EditItemTempla te>
<asp:DropDownLi st id=List_Edit_Ty pe runat="server" DataSource="<%# GetTypes() %>" SelectedIndex=' <%# DataBinder.Eval (Container, "DataItem.item_ typeID") %>'></asp:DropDownLis t>
</EditItemTemplat e>
</asp:TemplateCol umn>
My problem is that when I try to populate the EditItemTemplat e's DDL from the same dataset that is used to populate the FooterItemTempl ate's DDL I get the following error:

Stack Trace:
[ArgumentOutOfRa ngeException: Specified argument was out of the range of valid values.
Parameter name: value]
System.Web.UI.W ebControls.List Control.set_Sel ectedIndex(Int3 2 value)
System.Web.UI.W ebControls.Drop DownList.set_Se lectedIndex(Int 32 value)
System.Web.UI.W ebControls.List Control.OnDataB inding(EventArg s e)
System.Web.UI.C ontrol.DataBind ()
System.Web.UI.C ontrol.DataBind ()
System.Web.UI.C ontrol.DataBind ()
System.Web.UI.W ebControls.Data Grid.CreateItem (Int32 itemIndex, Int32 dataSourceIndex , ListItemType itemType, Boolean dataBind, Object dataItem, DataGridColumn[] columns, TableRowCollect ion rows, PagedDataSource pagedDataSource )
System.Web.UI.W ebControls.Data Grid.CreateCont rolHierarchy(Bo olean useDataSource)
System.Web.UI.W ebControls.Base DataList.OnData Binding(EventAr gs e)
System.Web.UI.W ebControls.Base DataList.DataBi nd()
Alumawood.diy_i tems.MyDataGrid _Edit(Object sender, DataGridCommand EventArgs e) in C:\Inetpub\Cele rity-Designs\Alumawo od\admin\diy_it ems.aspx.vb:125
System.Web.UI.W ebControls.Data Grid.OnEditComm and(DataGridCom mandEventArgse)
System.Web.UI.W ebControls.Data Grid.OnBubbleEv ent(Object source, EventArgs e)
System.Web.UI.C ontrol.RaiseBub bleEvent(Object source, EventArgs args)
System.Web.UI.W ebControls.Data GridItem.OnBubb leEvent(Object source, EventArgs e)
System.Web.UI.C ontrol.RaiseBub bleEvent(Object source, EventArgs args)
System.Web.UI.W ebControls.Butt on.OnCommand(Co mmandEventArgs e)
System.Web.UI.W ebControls.Butt on.System.Web.U I.IPostBackEven tHandler.RaiseP ostBackEvent(St ring eventArgument)
System.Web.UI.P age.RaisePostBa ckEvent(IPostBa ckEventHandler sourceControl, String eventArgument)
System.Web.UI.P age.RaisePostBa ckEvent(NameVal ueCollection postData)
System.Web.UI.P age.ProcessRequ estMain()


Version Information: Microsoft .NET Framework Version:1.1.432 2.573; ASP.NET Version:1.1.432 2.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 4788

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

Similar topics

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 the grid population event and the other is to populate the dropdownlist I'll start with the method that binds the dropdownlist. As mentioned it is object based and also works fine everywhere but in a template column. I have put in some comments...
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) e.Item.FindControl("DdlTest") enables me to work with ddlTest - with, for example, ddlTest.SelectedValu However, in DataGrid1_EditCommand, ddlTest.SelectedValue returns "Object reference not set to an instance of an object.
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 <asp:EditCommandColumn> I want either a textbox or dropdown to appear when I check what is being edited. I thought I could create the dropdown on the fly and add it to the datagrid as below but It's not appearing. I imagined I could populate the dropdown
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 be really grateful for any assistance! Thanks
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 show the current value in edit mode. I'm sure this is a common question. I've reviewed several related post and tried them out to no avial. Some of the offerings in listgroup look right on, but are not clear on where to handle the suggested...
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 when trying to locate my DropDownList so that I can populate it. It doesn't find the control Here is what I have: asp.net:
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 and an additional buttoncolumn where I used a delete button to delete a specific row. Once I had finished that, I trnsformed the grid tso it will display a dropdownlist indtead of a textbox. After much grappling, I pretty much have
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 to a DataSet. If i include an if statement to prevent the data binding from occuring on a page PostBack in the following way:
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 compile time errors stating the control doesn't exist in the current content: <asp:DataGrid ID="tmp" runat="server"> <Columns>
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.