c# gridview row click

后端 未结 9 1941
野的像风
野的像风 2020-12-01 09:34

When I click on a row in my GridView, I want to go to a other page with the ID I get from the database.

In my RowCreated event I have the following line:

         


        
9条回答
  •  生来不讨喜
    2020-12-01 10:20

    protected void gvSearch_RowDataBound(object sender, GridViewRowEventArgs e)  
    {     
     if (e.Row.RowType == DataControlRowType.DataRow)
            {
                GridViewRow gvr = e.Row;
                string abc = ((GridView)sender).DataKeys[e.Row.RowIndex].Value.ToString();         
                gvr.Attributes.Add("OnClick", "javascript:location.href='Default.aspx?id=" + abc + "'");
            }         
    
       }  
    }  
    

提交回复
热议问题