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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Jim Van DickPosted Dec 22, 2006, 8:50 AM
Post the code behind where you attempt to access the DDL info. I need to see how you are accessing the DDL.
Ndayahundwa ClaudePosted Dec 22, 2006, 3:57 AM
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 DickPosted Dec 21, 2006, 1:01 PM
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 ClaudePosted Dec 19, 2006, 6:42 AM
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 ClaudePosted Dec 19, 2006, 6:33 AM
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.
shekhar pawarPosted Dec 19, 2006, 4:01 AM
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.