我有一个gridview,有一些列。我想隐藏一列,但在选择记录时仍然可以访问它的值。
有人可以帮助我实现这个目标吗?
感谢任何帮助。
这是我的gridview:OutlookID是要隐藏的列!
<asp:GridView ID="gvOutlookMeldingen" runat="server"
AllowSorting="True" AutoGenerateColumns="False"
AutoGenerateSelectButton="True" onselectedindexchanged="GridView_SelectedIndexChanged">
<Columns>
<asp:BoundField DataField="Melder" HeaderText="Melder" />
<asp:BoundField DataField="Onderwerp" HeaderText="Onderwerp" />
<asp:TemplateField HeaderText="Omschrijving">
<ItemTemplate>
<div style="overflow:auto; width: 500px; height: 150px;">
<asp:Label ID="lblOmschrijving" runat="server" Text='<%# Bind("Omschrijving")%>'></asp:Label>
</div>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Meldingsdatum" HeaderText="Meldingsdatum" />
<asp:BoundField DataField="OutlookID" HeaderText="OutlookID" Visible="false" />
</Columns>
</asp:GridView>
这是我选择记录时的代码:
Label lblOmschrijving = (Label)gvOutlookMeldingen.SelectedRow.FindControl("lblOmschrijving");
//Label lblOutlookID = (Label)gvOutlookMeldingen.SelectedRow.FindControl("lblOutlookID");
Response.Redirect("Detailscherm.aspx?"
+ "melder=" + Server.UrlEncode(gvOutlookMeldingen.SelectedRow.Cells[1].Text)
+ "&meldingsdatum=" + gvOutlookMeldingen.SelectedRow.Cells[4].Text
+ "&onderwerp=" + Server.UrlEncode(gvOutlookMeldingen.SelectedRow.Cells[2].Text)
+ "&outlookid=" + Server.UrlEncode(gvOutlookMeldingen.SelectedRow.Cells[5].Text)
+ "&omschrijving=" + Server.UrlEncode(lblOmschrijving.Text)
+ "&niv1=" + ""
+ "&niv2=" + "");
答案 0 :(得分:4)
在绑定数据后设置此代码。要获得此功能,我执行此操作:
MyGridView.Columns[0].visible = true;
MyGridView.DataBind();
MyGridView.Columns[0].visible = false;
这样就隐藏了第一列,但你应该能够访问它的值。
答案 1 :(得分:0)
如果您不希望数据在客户端可用,则必须设置您正在使用的DataControlField的服务器端Visible = "False"
属性(最好在标记)。您仍然可以从服务器端访问该列。
您可能需要考虑使用GridView的DataKeys属性 - 它可能更适合您的需求。
答案 2 :(得分:0)
创建模板列而不是SELECT按钮。设置
一项PostBackUrl ='&LT;%# 的eval( “SomePage.aspx页面?ID = {0}”,“通缉令 列“)%&gt;'
。通过设计师删除列。
答案 3 :(得分:0)
您也可以在客户端将其设置为不可见。使用Javascript。
document.getElementById(myObject).visible = "false";
答案 4 :(得分:0)
当我们在设计时设置visiblity of control false时,将无法渲染。尝试 在gridView rowCreated事件中设置visiblity = false。我正在设置下面的代码 第二列visibility = false
protected void grid_RowCreated(object sender,GridViewRowEventArgs e) { if(e.Row.RowType == DataControlRowType.DataRow) { e.Row.Cells [2] .Visible = false;
}
if (e.Row.RowType == DataControlRowType.Header)
{
e.Row.Cells[2].Visible = false;
}
if (e.Row.RowType == DataControlRowType.Footer)
{
e.Row.Cells[2].Visible = false;
}
}
现在尝试获得价值。当然你会得到价值。
答案 5 :(得分:0)
我遇到了同样的问题。
您无法隐藏列并保留代码中的值。
您必须使用javascript直接在客户端隐藏它。
我做到了:
在我的css或页面上:
<style type="text/css">
.hiddencol
{
display: none;
}
.viscol
{
display: block;
}
</style>
然后将样式添加到gridViewer的BoundField中。
例如:
<asp:BoundField DataField="AgentGUID" HeaderText="AgentGUID" ReadOnly="True" SortExpression="AgentGUID"
meta:resourcekey="BoundFieldResource1">
<HeaderStyle CssClass="hiddencol" />
<ItemStyle CssClass="hiddencol" />
<FooterStyle CssClass="hiddencol" />
</asp:BoundField>