Does someone know if it is possible to add the dropdownlists in the gridview control for all the columns ? I have a requirement that when the user clicks the Add button, the columns in the gridview change to dropdownlist and the user has the option of adding
the values fom there and save it to the table linked to the gridview.
Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as
Answer” if a marked post does not actually answer your question.
Does someone know if it is possible to add the dropdownlists in the gridview control for all the columns ? I have a requirement that when the user clicks the Add button, the columns in the gridview change to dropdownlist and the user has the option of adding
the values fom there and save it to the table linked to the gridview.
Thanks.
Is your Add Button located outside the Grid? Also if you've set up your Grid like what you have in your previous
thread then you would probably need to create a separate GridView that would allow you to turn all columns to DropDownList. The idea is once you click on the Add Button the new grid with dropdownlist columns will show up, from there you can save the selected
item to your database. After saving you can show your other grid for them to edit/update and delete data and hide the grid with the dropdownlist.
Do you have a sample code or something I can refer to with regards to this ?
You'll just have to replace your TextBox with a DropDownlist control within your Grid's EditItemTemplate. Now if you want to bind your DropDown with data from database then you can handle RowDataBound event. You wound need to use FindControl method to access
the control and then bind them accordingly with the data. See if this helps:
http://www.codeproject.com/Articles/37207/Editable-Gridview-with-Textbox-CheckBox-Radio-Butt
lahsiv2004
Member
30 Points
179 Posts
Dropdownlist in Gridview
Feb 07, 2013 09:58 AM|LINK
Hi,
Does someone know if it is possible to add the dropdownlists in the gridview control for all the columns ? I have a requirement that when the user clicks the Add button, the columns in the gridview change to dropdownlist and the user has the option of adding the values fom there and save it to the table linked to the gridview.
Thanks.
rambhopalred...
Member
671 Points
214 Posts
Re: Dropdownlist in Gridview
Feb 07, 2013 10:02 AM|LINK
Use below links for your requirement.
http://forums.asp.net/t/1274055.aspx/1
http://www.aspsnippets.com/Articles/Adding-Dynamic-Rows-in-GridView-with-DropDownLists-in-ASP.Net.aspx
http://www.highoncoding.com/Articles/169_DropDownList_Inside_GridView__Method_1_.aspx
Rambhopal Reddy E
Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as
Answer” if a marked post does not actually answer your question.
goel.ankit
Contributor
2531 Points
513 Posts
Re: Dropdownlist in Gridview
Feb 07, 2013 10:02 AM|LINK
yes it is possible. Have the template columns with Dropdown
http://www.codeproject.com/Articles/53559/Accessing-a-DropDownList-inside-a-GridView
http://msdn.microsoft.com/en-us/library/ms178294%28v=vs.80%29.aspx
http://stackoverflow.com/questions/8152925/how-to-bind-dropdownlist-in-gridview-with-data-not-from-gridview
Ankit
(Please select 'Mark as Answer' if my response has helped you.)
Sujeet Saste
Contributor
2998 Points
572 Posts
Re: Dropdownlist in Gridview
Feb 07, 2013 10:04 AM|LINK
Something same solutions to your requirement in the following links, please refer :
http://aspsnippets.com/Articles/Adding-Dynamic-Rows-in-ASP.Net-GridView-Control-with-TextBoxes.aspx
http://www.codeproject.com/Articles/20237/Extended-GridView-with-Insert-Functionality
Do FEAR (Face Everything And Rise)
Please mark as Answer if my post helps you..!
My Blog
lahsiv2004
Member
30 Points
179 Posts
Re: Dropdownlist in Gridview
Feb 07, 2013 10:36 AM|LINK
I have created the attached code but the columns still show up as static and do not display any dropdown values.
Thanks.
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e) { string id = GridView1.Rows[e.RowIndex].Cells[0].Text; string Function = ((DropDownList)GridView1.Rows[e.RowIndex].Cells[1].FindControl("DropDownList1")).Text; //Function string System = ((DropDownList)GridView1.Rows[e.RowIndex].Cells[2].FindControl("DropDownList2")).Text; //System string Interface = ((DropDownList)GridView1.Rows[e.RowIndex].Cells[3].FindControl("DropDownList3")).Text; // Interface UpdateOrAddNewRecord(id, Function, System, Interface, true); // call update method GridView1.EditIndex = -1; BindGridView(); // Rebind GridView to reflect changes made }vinz
All-Star
126896 Points
17922 Posts
MVP
Re: Dropdownlist in Gridview
Feb 07, 2013 10:41 AM|LINK
Is your Add Button located outside the Grid? Also if you've set up your Grid like what you have in your previous thread then you would probably need to create a separate GridView that would allow you to turn all columns to DropDownList. The idea is once you click on the Add Button the new grid with dropdownlist columns will show up, from there you can save the selected item to your database. After saving you can show your other grid for them to edit/update and delete data and hide the grid with the dropdownlist.
MessageBox Controls for WebForms | Blog | Twitter | Linkedin
lahsiv2004
Member
30 Points
179 Posts
Re: Dropdownlist in Gridview
Feb 07, 2013 02:07 PM|LINK
Yes, the Add button is located outside the gridview. Do you have a sample code or something I can refer to with regards to this ?
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Dropdownlist in Gridview
Feb 09, 2013 12:41 AM|LINK
Just follow the steps:
1) Drag and drop a GridView onto the aspx page.
2) Then set AutoGeneratedColumns=False.
3) Then Create several TemplateFields.
4) In their ItemTemplate, please put some Dropdownlists.
raghavendra ...
Participant
1890 Points
435 Posts
Re: Dropdownlist in Gridview
Feb 09, 2013 03:47 AM|LINK
Try this
<asp:TemplateField HeaderText="Mode of travel"> <EditItemTemplate> <asp:DropDownList ID="DDLMOT" runat="server" BorderColor="DarkGray" Width="80px" BorderStyle="Solid" BorderWidth="1px"> <asp:ListItem>Select a Type</asp:ListItem> <asp:ListItem Value="Local">LOCAL</asp:ListItem> <asp:ListItem Value="Global">GLOBAL</asp:ListItem> </asp:DropDownList> </EditItemTemplate> <ItemTemplate> <asp:Label ID="Label4" runat="server" Text='<%# Bind("fld_vehicle_type_name") %>'></asp:Label> </ItemTemplate> </asp:TemplateField>vinz
All-Star
126896 Points
17922 Posts
MVP
Re: Dropdownlist in Gridview
Feb 11, 2013 12:38 PM|LINK
You'll just have to replace your TextBox with a DropDownlist control within your Grid's EditItemTemplate. Now if you want to bind your DropDown with data from database then you can handle RowDataBound event. You wound need to use FindControl method to access the control and then bind them accordingly with the data. See if this helps: http://www.codeproject.com/Articles/37207/Editable-Gridview-with-Textbox-CheckBox-Radio-Butt
MessageBox Controls for WebForms | Blog | Twitter | Linkedin