是这样,我用GridView的“选择列”,选择GridView1的某一列时,在这个页面上的另一个GridView2显示相应的信息,GridView2是根据GridView1的字段“id”来关联的。代码:
string id = GridView1.SelectedRow.Cell[0].Text.Trim();
这样就能获得id了,但是一旦我将GridView1的id列隐藏起来,即将id字段的visible属性设为false时,id就找不到了(Cell[0]就不是id了)。03里DataGrid就可以找到,怎么05就不行了呀,奇怪。求助!!谢谢了。

解决方案 »

  1.   

    GridView的Cell在浏览器种对应<td>标签的。隐藏列在浏览器中是不生成<td>标签的,所以就没有Cell。如果有5列,其中隐藏了一列,那么,只会有4个Cell。
    你可以用DataKey这个属性,将关联列放到这个属性中。
      

  2.   

    一楼正解,如果你想用的话,可将cell[0]的样式设为 display:none
      

  3.   

    隐藏列放DataKey里
    string id = gridLwdb.SelectedDataKey["AF02"].ToString();
      

  4.   

    用模板
    <asp:TemplateColumn>
                                 <ItemTemplate>
                                     <asp:TextBox ID="TextBoxIdynamic_table" runat="server" Visible="False"  Text=<%# DataBinder.Eval(Container,"DataItem.Idynamic_table")%> Width="0px"></asp:TextBox>
                                 </ItemTemplate>
                             </asp:TemplateColumn>后台取值
    ((TextBox)e.Item.Cells[i].Controls[1]).Text
      

  5.   

    Sorry
    用以下这种比较好
    <asp:TemplateColumn><ItemTemplate><input id="HiddenIdynamic_table" runat="server" value=<%# DataBinder.Eval(Container,"DataItem.Idynamic_table")%> type="hidden" />
                                 </ItemTemplate>其是<ItemTemplate>和<input>之间不能有空格或
    将其写成两行
    <ItemTemplate>
        <input>
    否则后台找值时找((HtmlInputHidden)e.Item.Cells[i].Controls[0]).Value会出错
    如果有空格或回车则找Controls[0]找不到...