asp.net c# Gridview row click function

2019-09-03 07:53发布

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条回答
小情绪 Triste *
2楼-- · 2019-09-03 07:59

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....
        }
    }
}
查看更多
登录 后发表回答