【问题标题】:GridView Column VisibilityGridView 列可见性
【发布时间】:2013-05-08 02:46:23
【问题描述】:

在我的 GridView 中,我有名为“F Notes”、“P Notes”的列和一个 ImageColumn。单击 ImageButton 后,会打开一个弹出窗口,显示“F Notes”和“P Notes”中的数据。现在我的问题是,当弹出窗口打开时,我不希望在后台显示“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;
    }

【问题讨论】:

  • 可以发Popup的方法吗?
  • 嗨 mshsayem,下面是我的弹出窗口方法 protected void Popup(object sender, EventArgs 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_ModalPopupExtender.Show(); }
  • 这可能会有所帮助:stackoverflow.com/questions/2818203/…

标签: c# html asp.net


【解决方案1】:

正如“mshsayem”所建议的(“Get DataKey values in GridView RowCommand”),我相信您可以通过在 GridView 中将“FNotes”和“PNotes”定义为 DataKeys 来绕过可见性问题。 也更改 GridView 中的 DataKeyNames:

DataKeyNames="MrNumber,FNotes,PNotes"

然后在您的“Popup”中引用之前定义的 DataKeys 而不是从单元格本身获取数据。

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(); 
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多