asp.net c# Gridview row click function

℡╲_俬逩灬. 提交于 2019-12-11 18:38:45

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!