I would like to be able to bulk edit all the rows for one column using a GridView control. What is the best way to do this?
A:
I guess u know this: http://msdn.microsoft.com/en-us/library/ms972948.aspx
iPhoneDev
2010-05-27 04:53:03
Yes, thanks for the answer. That only allows you to edit one row at a time. I would like to edit all the rows for one column.
Joel Cunningham
2010-05-27 04:58:20
+1
A:
If you want to update all rows with same value then show proper control(textbox/dropdown/checkbox/radio) in column header else show the grid column in edit mode instead of label.
See following:
http://www.codeproject.com/KB/webforms/BulkEditGridView.aspx
Brij
2010-05-27 04:54:15
I ended up using a similar approach to this control by inheriting from GridView and overriding the CreateRow event.
Joel Cunningham
2010-06-03 22:25:57
A:
Probably not the best, but an option is to set the primary key of your table as the DataKey of the GridView then iterate the grid and use the datakey and the edited value to update the DB. Here is an example.
<asp:GridView ID="GridView1" runat="server" DataKeyNames="ID">
<Columns>.....
foreach (var item in GridView1.Items)
{
var id = (Guid)GridView1.DataKeys[item.DataItemIndex].Value;
var txt= item.FindControl("AmountTextBox") as Textbox;
if (cb != null && id.HasValue)
UpdateRow(id.Value, txt.Text);
}
alejandrobog
2010-05-27 04:56:36