问题
I have gridview1
on sample.asp
page. It has about 15 rows. What i want to do is:
If i click on a row (say row 7) in the gridview1, it should update a few other rows (say rows 2,3,4) in the same gridview. On clicking the row, I want to call the function UpdateOnClick()
that is already present in the sample.asp.cs
file. This function should change the values in the desired rows on the same gridview.
I want to update a few other rows on the same gridview
how can i achieve this?
回答1:
You can call the UpdateOnClick from the OnRowCommand, the CommandEventArgs (which most people call e) gives the selected row in its CommandArgument property.
From this, you can iterate through the rows to find the ones you want. This should give you enough copy and paste food anyway:
protected void GridView1_OnRowCommand(object sender, GridViewCommandEventArgs e)
{
int rownum = Convert.ToInt32(e.CommandArgument.ToString());
foreach(GridViewRow row in sender.Rows)
{
if(row.Cells[0].Text == "a-value-")
{
// Do something....
}
}
}
来源:https://stackoverflow.com/questions/5499319/asp-net-c-sharp-gridview-row-click-function