I am working on building a process with my gridview that would allow a user to provide one edit and save it to multiple records. So far I've gotten to this point of planning but not sure of how the best way would be to build an array of record ID's to be included in this edit.
Here is what I'm kicking around right now...
Everything except the CheckBoxes in the GridView would be processed outside of the GridView and upon completion the GridView would be redrawn clearing the CheckBoxes and displaying the updated column values in those cells that were modified.
For the sake of understanding what I'm tinkering with here I've provided a screen shot of the left side of the GridView:
Thoughts on building the array from the CheckBoxes?
UPDATE 04/13/17 1PM Central US
Adding the code I added to approach the population of an array from the CheckBoxes per example #2 below...
protected void ColumnSelectDDL_TextChanged(object sender, EventArgs e)
{
foreach (GridViewRow row in ActVulListGV.Rows)
{
var ri = -1;
if (row.RowType == DataControlRowType.DataRow)
{
CheckBox chk = (row.Cells[0].FindControl("chkid") as CheckBox);
if (chk.Checked)
{
// Create and append your array here
var recnumbers = new int[0];
++ri;
{
Label REC = (row.Cells[1].FindControl("RecID") as Label);
recnumbers[ri] = Convert.ToInt32(REC.Text);
}
recnumbers.ToList().ForEach(i => Console.WriteLine(i.ToString()));
}
}
}
}
You can bind the array of checkboxes at the time of Rowdatabound (Option 1) or after Gridview bound onclick on Save button create the loop of grid rows (Option 2).
Option 1:
protected void OnRowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow) {
CheckBox chk = (row.Cells[0].FindControl("chkid") as CheckBox);
if (chk.Checked)
{
//Create the hiddenfield or viewstate which you can access page level.
}
}
}
Option 2 :
foreach (GridViewRow row in GridView1.Rows)
{
if (row.RowType == DataControlRowType.DataRow)
{
CheckBox chk = (row.Cells[0].FindControl("chkid") as CheckBox);
if (chk.Checked)
{
// Create and append your array here
}
}
}
Hope this helps.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.