Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I am not an expert in BulkEditGridView control, but this is what I found at Matt Dotson's <a href="http://blogs.msdn.com/b/mattdotson/archive/2005/11/09/real-world-gridview-bulk-editing.aspx" rel="nofollow">blog entry</a></p> <p>You may not be able to know that the row has been updated, unless you watch for the change explicitly. First, for each row add a change handler</p> <pre><code>protected override void InitializeRow(GridViewRow row, DataControlField[] fields) { base.InitializeRow(row, fields); foreach (DataControlFieldCell cell in row.Cells) { if (cell.Controls.Count &gt; 0) { AddChangedHandlers(cell.Controls); } } } </code></pre> <p>You can use this snippet</p> <pre><code>private void AddChangedHandlers(ControlCollection controls) { foreach (Control ctrl in controls) { if (ctrl is TextBox) { ((TextBox)ctrl).TextChanged += new EventHandler(this.HandleRowChanged); } else if (ctrl is CheckBox) { ((CheckBox)ctrl).CheckedChanged += new EventHandler(this.HandleRowChanged); } else if (ctrl is DropDownList) { ((DropDownList)ctrl).SelectedIndexChanged += new EventHandler(this.HandleRowChanged); } } } </code></pre> <p>Then you define a dirty row list and add rows that needs to be updated there (in the event handler)</p> <pre><code> private List&lt;int&gt; dirtyRows = new List&lt;int&gt;(); void HandleRowChanged(object sender, EventArgs args) { GridViewRow row = ((Control) sender).NamingContainer as GridViewRow; if (null != row &amp;&amp; !dirtyRows.Contains(row.RowIndex)) { dirtyRows.Add(row.RowIndex); } } </code></pre> <p>Finally, to commit changes, iterate through all the dirty rows and save changes</p> <pre><code> public void Save() { foreach (int row in dirtyRows) { this.UpdateRow(row, false); } dirtyRows.Clear(); } </code></pre> <p>And here is your ASPX code</p> <pre><code>&lt;asp:Button runat="server" ID="SaveButton" Text="Save Data" /&gt; &lt;blog:BulkEditGridView runat="server" id="EditableGrid" DataSourceID="AdventureWorks" AutoGenerateColumns="False" DataKeyNames="LocationID" SaveButtonID="SaveButton" &gt; &lt;Columns&gt; &lt;asp:BoundField DataField="LocationID" HeaderText="LocationID" InsertVisible="False" ReadOnly="True" SortExpression="LocationID" /&gt; &lt;asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" /&gt; &lt;asp:BoundField DataField="Availability" HeaderText="Availability" SortExpression="Availability" /&gt; &lt;asp:BoundField DataField="CostRate" HeaderText="CostRate" SortExpression="CostRate" /&gt; &lt;/Columns&gt; &lt;/blog:BulkEditGridView&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload