Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Dec 21, 2012 12:46 PM by sloaner
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!
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
Dec 19, 2012 03:20 AM|LINK
I think you need to update the current row where you changed the gridview items,
Try like the following
<asp:TextBox ID="txtEAddress" Width="100px" runat="server" Text='<%# Bind("Address") %>'></asp:TextBox>
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"
<asp:Label ID="Label3" runat="server" Text='<%# Bind("Address") %>'></asp:Label>
<asp:TextBox ID="txtAddress" runat="server" Width="100px" TextMode="MultiLine"></asp:TextBox>
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.FindControl("txtECustCode");
string _text1 = txtECustCode.Text.ToString();
'You can udate here using some queries to DB
Dec 20, 2012 12:16 AM|LINK
Is it possible to have a dropdownlist, in a gridview, when an item is selected, it updates the current rows record?
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.
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.