2013-05-13 87 views
0

在我的GridView中,我有名为'F Notes','P Notes'和ImageColumn的列。点击ImageButton后,弹出窗口打开,显示'F Notes'和'P Notes'中的数据。现在我的问题是我不想在弹出窗口打开时在后台显示'F Notes'和'P Notes'列。我希望数据仅在弹出窗口中可见。我知道如果我更改Visible = false,那么该列将不会显示,但是当我这样做时,弹出窗口中的文本不可见。GridView列可见性

下面是我为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; 
    } 
+0

你可以发布'Popup'方法吗? – mshsayem 2013-05-14 01:38:31

+0

嗨mshsayem,下面是我的弹出窗口保护无效弹出窗口(对象发件人,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(); } – Valley 2013-05-14 16:14:36

+0

这可能有所帮助:http://stackoverflow.com/questions/2818203/get-datakey-values-in-gridview-rowcommand – mshsayem 2013-05-15 01:39:52

回答

0

为“mshsayem”建议(“Get DataKey values in GridView RowCommand”),我相信,你可以通过定义‘FNotes’绕过知名度的问题,在您的GridView中将“PNotes”作为DataKeys。在你的GridView太 变化的DataKeyNames:

DataKeyNames="MrNumber,FNotes,PNotes" 

然后在您的“弹出式”引用先前定义的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(); 
}