Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/29.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
如何在ASP.net中获取不可见的gridview单元格值?_Asp.net_Gridview - Fatal编程技术网

如何在ASP.net中获取不可见的gridview单元格值?

如何在ASP.net中获取不可见的gridview单元格值?,asp.net,gridview,Asp.net,Gridview,我有一个如下所示的网格 <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" s onrowcommand="GridView1_RowCommand"> <Columns> <asp:ButtonField Da

我有一个如下所示的网格

 <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" s                                      
                                    onrowcommand="GridView1_RowCommand">
  <Columns>
      <asp:ButtonField DataTextField="Name" HeaderText="Name" />
      <asp:BoundField DataField="ArrDate" DataFormatString="{0:MM/dd/yyyy}" 
                              HeaderText="Arr Date" />
      <asp:BoundField HeaderText="Dep Date" DataField="DepDate" 
                           DataFormatString="{0:MM/dd/yyyy}" />
      <asp:BoundField HeaderText="Mail" DataField="Mail" />
      <asp:BoundField HeaderText="Status" DataField="Status" />
      <asp:BoundField DataField="ResId" HeaderText="ResId" Visible="False" />                                        
  </Columns>
</asp:GridView>
现在消息显示-RegId=

我无法得到这个值。因此,我将RedId BoundField更改为vissible。现在我得到了价值

这就是RegId=6

我现在有两个问题-

1) 如何在不可见列中获取RegId值。 2) 如何查找单击的行值。。。bzs是唯一可以在代码中更改行值的

 string text = GridView1.Rows[ROWVALUE].Cells[5].Text;

这肯定不是正确的做法。您可能想看看如何使用DataKeys来实现这一点。使用当前方法,当您向网格中添加一个新列时,您的代码将失败

  • 在gridview的DataKeys属性中添加RegId列
  • 在codebehind中引用当前行的gridview数据键,如下所示

     int regId= Convert.ToInt32(YourGridview.DataKeys[rowIndex]["RegId"].ToString());
    

  • 或者使用Templatefields、Row命令、FindControl。样本:
     int regId= Convert.ToInt32(YourGridview.DataKeys[rowIndex]["RegId"].ToString());