简体   繁体   中英

asp.net c# Gridview row click function

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?

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....
        }
    }
}

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM