I have worked on this for a couple of nights now. Is it possible to have a dropdownlist, in a gridview, when an item is selected, it updates the current rows record? I have the gridview created with the ddl and can retreive field values if I specify the
row, but I cannot figure out how to do this with the selected row (row of the updated ddl).
My buddies will be using this to update 900 ddl's and I know that they would not want to click Update, choose ddl and then click save. I was thinking that they could start on the first record, choose the correct item and then move down the gridview.
I hope you can write a code behind for selected index changed event for the Drop down
make sure its run at server proeprty is set.
But I think this will not be a good idea to allow per row update, so if u r not using AJAX the page must be refreshed, binding
the grid view again to show updated record. If u sort out the refresh issue with AJAX, even then it will be not a good approach
as still u r not saving the server side execution
How about placing an updated button below or above the grid view, let the users choose options from Drop down
and in that update button code, you can loop through the rows to detect any changed value to store it in the DB
Is it possible to have a dropdownlist, in a gridview, when an item is selected, it updates the current rows record?
Hi,
To be very honest, this can be done:
1) If you wanna directly do to cope with the problem by designing something directly in asp.net design mode, it cannot be possible.
2) But if you wanna do that, I can tell you a "trick" that you can:
2.1) handle the event of Dropdownlist's SelectIndexChanged.
2.2) Make your Dropdownlist's AutoPostBack = True.
2.3) In the event, please convert back to Dropdownlist and then fetch its NamingContainer (it should be a GridViewRow), and then find out the other values of the GridView and you can use SqlCommand to cope with the problem.
sloaner
0 Points
3 Posts
DDL used to execute Update in Gridview
Dec 18, 2012 11:39 PM|LINK
I have worked on this for a couple of nights now. Is it possible to have a dropdownlist, in a gridview, when an item is selected, it updates the current rows record? I have the gridview created with the ddl and can retreive field values if I specify the row, but I cannot figure out how to do this with the selected row (row of the updated ddl).
My buddies will be using this to update 900 ddl's and I know that they would not want to click Update, choose ddl and then click save. I was thinking that they could start on the first record, choose the correct item and then move down the gridview.
Help would greatly be appreciated!
usman400
Contributor
3493 Points
721 Posts
Re: DDL used to execute Update in Gridview
Dec 19, 2012 03:13 AM|LINK
I hope you can write a code behind for selected index changed event for the Drop down
make sure its run at server proeprty is set.
But I think this will not be a good idea to allow per row update, so if u r not using AJAX the page must be refreshed, binding
the grid view again to show updated record. If u sort out the refresh issue with AJAX, even then it will be not a good approach
as still u r not saving the server side execution
How about placing an updated button below or above the grid view, let the users choose options from Drop down
and in that update button code, you can loop through the rows to detect any changed value to store it in the DB
sarathi125
Star
13599 Points
2691 Posts
Re: DDL used to execute Update in Gridview
Dec 19, 2012 03:20 AM|LINK
Hi,
I think you need to update the current row where you changed the gridview items,
Try like the following
Gridview Markup <asp:TemplateField HeaderText="Address"> <EditItemTemplate> <asp:TextBox ID="txtEAddress" Width="100px" runat="server" Text='<%# Bind("Address") %>'></asp:TextBox> <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" onselectedindexchanged="DropDownList1_SelectedIndexChanged"> <asp:ListItem>4</asp:ListItem> <asp:ListItem>3</asp:ListItem> <asp:ListItem>2</asp:ListItem> <asp:ListItem>1</asp:ListItem> </asp:DropDownList> </EditItemTemplate> <ItemTemplate> <asp:Label ID="Label3" runat="server" Text='<%# Bind("Address") %>'></asp:Label> </ItemTemplate> <FooterTemplate> <asp:TextBox ID="txtAddress" runat="server" Width="100px" TextMode="MultiLine"></asp:TextBox> </FooterTemplate> </asp:TemplateField> Code Behind protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) { DropDownList ddl = (DropDownList)sender; GridViewRow row = (GridViewRow)ddl.Parent.Parent; int idx = row.RowIndex; TextBox txtECustCode = (TextBox)row.Cells[0].FindControl("txtECustCode"); string _text1 = txtECustCode.Text.ToString(); 'You can udate here using some queries to DB }Remember to click Mark as Answer on the post that helps to others.
My Blog :MyAspSnippets
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: DDL used to execute Update in Gridview
Dec 20, 2012 12:16 AM|LINK
Hi,
To be very honest, this can be done:
1) If you wanna directly do to cope with the problem by designing something directly in asp.net design mode, it cannot be possible.
2) But if you wanna do that, I can tell you a "trick" that you can:
2.1) handle the event of Dropdownlist's SelectIndexChanged.
2.2) Make your Dropdownlist's AutoPostBack = True.
2.3) In the event, please convert back to Dropdownlist and then fetch its NamingContainer (it should be a GridViewRow), and then find out the other values of the GridView and you can use SqlCommand to cope with the problem.
sloaner
0 Points
3 Posts
Re: DDL used to execute Update in Gridview
Dec 21, 2012 12:46 PM|LINK
Thanks for all the advice and help, but I ended up going with bulk update option I found. Thanks again for the awesome advice.