C# GridView列可见性

C# GridView列可见性,c#,html,asp.net,C#,Html,Asp.net,在我的GridView中,有名为“F注释”、“p注释”的列和一个ImageColumn。单击ImageButton(图像按钮)后,将打开一个弹出窗口,显示“F注释”和“P注释”中的数据。现在我的问题是,当弹出窗口打开时,我不希望“F Notes”和“P Notes”列显示在后台。我希望数据仅在弹出窗口中可见。我知道如果我更改Visible=false,那么该列将不会显示,但当我这样做时,弹出窗口中的文本将不可见 下面是我的HTML和aspx.cs代码: <asp:BoundField D

在我的GridView中,有名为“F注释”、“p注释”的列和一个ImageColumn。单击ImageButton(图像按钮)后,将打开一个弹出窗口,显示“F注释”和“P注释”中的数据。现在我的问题是,当弹出窗口打开时,我不希望“F Notes”和“P Notes”列显示在后台。我希望数据仅在弹出窗口中可见。我知道如果我更改Visible=false,那么该列将不会显示,但当我这样做时,弹出窗口中的文本将不可见

下面是我的HTML和aspx.cs代码:

 <asp:BoundField DataField="FNotes" HeaderText="F Notes" Visible="False" SortExpression="FNotes" />
 <asp:BoundField DataField="PNotes" HeaderText="P Notes" Visible="False" SortExpression="PNotes" />
 <asp:TemplateField HeaderText="Notes">
    <ItemTemplate>
      <asp:ImageButton ID="btnShowPopup" runat="server" Visible='<%#true.Equals(Eval("notesVisible"))%>' ImageUrl="~/Images/Imgs.jpg" Height="30px" Width="30px" OnClick="Popup" />
    </ItemTemplate>
  </asp:TemplateField>

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        GridView1.Columns[2].Visible = true;
        GridView1.Columns[3].Visible = true;
    }

受保护的void GridView1_row命令(对象发送方,GridViewCommandEventArgs e)
{
GridView1.Columns[2]。Visible=true;
GridView1.Columns[3]。Visible=true;
}
正如“mshsayem”所建议的(“”),我相信您可以通过在GridView中将“FNotes”和“PNotes”定义为数据键来绕过可见性问题。 在GridView中也更改DataKeyName:

DataKeyNames="MrNumber,FNotes,PNotes"
然后在“弹出窗口”中引用先前定义的数据键,而不是从单元格本身获取数据

protected void Popup(object sender, EventArgs e) { 
     ImageButton btndetails = sender as ImageButton; 
     GridViewRow gvrow = (GridViewRow)btndetails.NamingContainer; 
     lblMrNumber.Text = (string)GridView1.DataKeys[gvrow.RowIndex]["MrNumber"]; 
     lblMrNumber.Text = gvrow.Cells[6].Text; 
     txtFNotes.Text = (string)GridView1.DataKeys[gvrow.RowIndex]["FNotes"]; 
     txtPNotes.Text = (string)GridView1.DataKeys[gvrow.RowIndex]["PNotes"];  
     this.GridView1_ModalPopupExtender.Show(); 
}

你能发布
Popup
方法吗?您好,下面是我的Popup方法受保护的void Popup(对象发送者,事件参数e){ImageButton btndetails=sender as ImageButton;GridViewRow gvrow=(GridViewRow)btndetails.NamingContainer;lblMrNumber.Text=GridView1.DataKeys[gvrow.RowIndex].Value.ToString();lblMrNumber.Text=gvrow.Cells[6]。Text;txtFNotes.Text=gvrow.Cells[2]。Text;txtPNotes.Text=gvrow.Cells[3]。Text;this.GridView1_modalPopupXtender.Show();}这可能有帮助: