Hi,
I have a datagrid that is used to Update using textBox In asp.net/C#. But this time Ihave to update using DropDownList Could any one help me Please?
Loading
Hi,
I have a datagrid that is used to Update using textBox In asp.net/C#. But this time Ihave to update using DropDownList Could any one help me Please?
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
shekhar pawar71 reputationPosted Dec 18, 2006, 11:01 PM EST
Hi,
You need to use FindControl for datagrid dropdown in ItemCommand event or EditCommand event of Grid u r using.
Look code will be as follows.....where ddlTemp is ID of ur dropdownlist in datagrid.
string getSelectedValue = ((DropDownList)e.Item.FindControl("ddlTemp")).SelectedValue;
All the best.
Ndayahundwa Claude41 reputationPosted Dec 19, 2006, 1:33 AM EST
iy's my first time to use a DropDownList in a datagrid and I'm not good at all, I wanted actually When I press the Link button I wanted a DropDownList to come on the colomns I want to Edit and in the DropDownList Iwant to inserte in two words that the user can select one and update the column. I'm really stuck and I don't know where to start from.
Thank you for yr time.
Ndayahundwa Claude41 reputationPosted Dec 19, 2006, 1:42 AM EST
iy's my first time to use a DropDownList in a datagrid and I'm not good at all, I wanted actually When I press the Link button I wanted a DropDownList to come on the colomns I want to Edit and in the DropDownList Iwant to inserte in two words that the user can select one and update the column. I'm really stuck and I don't know where to start from.
Thank you for yr time.
Jim Van Dick16 reputationPosted Dec 21, 2006, 8:01 AM EST
I reponded to another posting about filling in the DDL. That still applies. You need to put that DDL in a Template column. See below:
<asp:TemplateColumn SortExpression="phase_no" HeaderText="Phase Number"> <HeaderStyle HorizontalAlign="Left" CssClass="grid-header" VerticalAlign="Middle">HeaderStyle> <ItemStyle Wrap="False" HorizontalAlign="Left" Width="30px" CssClass="grid-item" VerticalAlign="Middle">ItemStyle> <ItemTemplate> <asp:Label id="LblPhaseNumber" runat="server" Text=' <%# DataBinder.Eval(Container, "DataItem.PhaseNumber") %>'> asp:Label> ItemTemplate> <EditItemTemplate> <asp:dropdownlist id="DDLPhaseNumber" Width="60px" CssClass="Standard-text" Runat="server" DataValueField="PhaseId" DataTextField="PhaseNumber" DataSource="<%# GetPhaseList() %>"> asp:dropdownlist> EditItemTemplate> asp:TemplateColumn>
You define a Template Column. Within it, there is an Item Template which contains a label that you populate with the current value. When they go to edit, the EditItemTemplate gets called which contains you DDL. As I mentioned in your other post, define the data source as the method you fill the DDL with and then define the DataValueField with the current value. It then becomes editable with the current value!
Good luck.
Ndayahundwa Claude41 reputationPosted Dec 21, 2006, 10:57 PM EST
But I'm stuck again Could you tell me where I'm going Wrong? When I press Edit I get The dropdownlist properly I Select One option but when I update I get an error that: Object reference not set to an instance of object. could you Please help?
Thank you.
Jim Van Dick16 reputationPosted Dec 22, 2006, 3:50 AM EST
Post the code behind where you attempt to access the DDL info. I need to see how you are accessing the DDL.