Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/309.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 从选定行gridview获取单元格值_C#_Gridview_Selected - Fatal编程技术网

C# 从选定行gridview获取单元格值

C# 从选定行gridview获取单元格值,c#,gridview,selected,C#,Gridview,Selected,我有一个GridView,它有7列。其中6列具有链接按钮 我想做的是,当单击其中一个LinkButon时,获取第一列中的数据值,并将其放在页面其他位置的标签中 例如,第一列的值如下所示:01:00-02:00 到目前为止,我的GridView名为gvappts 我已添加此属性:OnRowDataBound=“gvappts\u DataBound” 在我的一个链接按钮上的gvappts中,我添加了命令和命令参数: 因为我想选择当前行 在我的.cs中,我有: protected void gvap

我有一个GridView,它有7列。其中6列具有链接按钮

我想做的是,当单击其中一个LinkButon时,获取第一列中的数据值,并将其放在页面其他位置的标签中

例如,第一列的值如下所示:01:00-02:00

到目前为止,我的GridView名为gvappts

我已添加此属性:
OnRowDataBound=“gvappts\u DataBound”

在我的一个链接按钮上的gvappts中,我添加了命令和命令参数:

因为我想选择当前行

在我的.cs中,我有:

protected void gvappts_RowCommand(object sender, System.Web.UI.WebControls.GridViewCommandEventArgs e)
    {
        if (e.CommandName == "GetData")
        {
            //Get rowindex
            int rowindex = Convert.ToInt32(e.CommandArgument);
            //Get Row
            GridViewRow gvr = gvappts.Rows[rowindex];
            //Set the label value
            lblTimeSelected.Text = gvr.Cells[0].Text;
        }
    }
我在单击按钮时没有收到任何错误,但没有返回任何值。我忽略了什么?

试试这个

 GridViewRow gvr = gvappts.Rows[rowindex];
 Label myLabel  = gvr.FindControl("MyLabel Id") as Label ;
 lblTimeSelected.Text = myLabel.Text;
试试这个

 GridViewRow gvr = gvappts.Rows[rowindex];
 Label myLabel  = gvr.FindControl("MyLabel Id") as Label ;
 lblTimeSelected.Text = myLabel.Text;

为什么不将同一源列绑定到绑定到网格第一列的
CommandArgument
。为什么不将同一源列绑定到绑定到网格第一列的
CommandArgument