日期:2014-05-17  浏览次数:20423 次

新手求指导
C#语言做网站,有一个gridview 分别有3个字段:Id,Name,Age,有3个变量分别为varId,varName,varAge。单击gridview的某一行,怎么取出这一行的值并赋给这3个变量变量

------解决方案--------------------
需要添加事件,比如在 RowEditing:
事件里用 this.GV.DataKeys[e.NewEditIndex].Value 取得 id

第二种也是用事件,如加个操作列,其中加个LinkButton:

<asp:LinkButton ID="lbdelete" runat="server" CommandName="rdelete" CommandArgument='<%#Eval("ID") %>'>删除</asp:LinkButton>
后台代码中
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)        
{                                                                                     
    if (e.CommandName == "rdelete")                                                   
    {                                                                                 
        string id = e.CommandArgument.ToString();                                     
        ......                                                                        
    }                                                                                 
}