如何隐藏gridview中的隐藏字段列。 [英] How to hide the hidden field column in gridview.
问题描述
我在Gridview中有一个隐藏字段,
当我用gridview绑定我的数据集时,我想要隐藏隐藏字段的列。
现在当我用gridview绑定我的数据集时,我的隐藏字段列是可见的。
有人可以帮帮忙吗?
< asp:TemplateField >
< ItemTemplate >
< asp:HiddenField < span class =code-attribute> ID = Internal_id runat = 服务器 值 =' <% #Eval( ID)%> ' / >
< / ItemTemplate >
< / asp:TemplateField > ;
当我写< asp:TemplateField Visible =false>
隐藏字段中的值为,但我希望隐藏字段中的值。
< blockquote>你应该隐藏列。不要将Visibility设置为false,否则它将不会呈现控件。
在 GridView中写下以下代码
RowCreated
事件。
这里Cell 0表示使用第一列。您必须将0替换为所需的列索引。
protected void OnRowCreated( object sender,GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Cells [ 0 ]。CssClass = < span class =code-string> hiddencol;
}
else if (e.Row.RowType == DataControlRowType.Header )
{
e.Row.Cells [ 0 ]。CssClass = hiddencol;
}
}
在 aspx
页面上写下以下CSS。
。 hiddencol
{
display : none;
}
您可以在客户端设置可见性为false// 条件当你想要隐藏
IdOfGrid.Columns [ 2 ]。可见= false ;
// 我假设它是你的第二列,如果不是你可以将它从2更改为任何列是
你好,
您可以在隐藏字段上使用Label。然后设置
< asp:TemplateField Visible =false>
获取标签值使用此
标签ID = dgvrow.Cells [6] .FindControl( lblid)作为标签;
//如果lblid是标签名称,它位于第6位
if(ID!= null)
int id = Convert.ToInt32(ID.Text);
并使用此id值进一步取得进展。
谢谢
I have a Hidden Field in Gridview ,
When i bind my dataset with gridview i want to hide the column of Hidden Field.
Now when i bind my dataset with gridview my hidden field column is visible.
Can anybody help out?
<asp:TemplateField >
<ItemTemplate>
<asp:HiddenField ID="Internal_id" runat="server" Value='<%# Eval("ID") %>' />
</ItemTemplate>
</asp:TemplateField>
when i write <asp:TemplateField Visible = "false" >
the value is "" in hidden field , but i want the value in my hidden field.
You should hide the Column. Don't set Visibility to false, otherwise it won't render the control.
Write below code inGridView
RowCreated
Event.
Here Cell 0 means first Column is used. You have to replace 0 with your required Column index.
protected void OnRowCreated(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { e.Row.Cells[0].CssClass = "hiddencol"; } else if (e.Row.RowType == DataControlRowType.Header) { e.Row.Cells[0].CssClass = "hiddencol"; } }
Write the following CSS on theaspx
page.
.hiddencol { display:none; }
you can set visibility false from client side//Condition when you want to hide IdOfGrid.Columns[2].Visible = false; // i am supposing it is your second column if not you can change it from 2 to whatever column it is
Hello ,
You can use Label instead on Hidden Field . then set
<asp:TemplateField Visible = "false" >
to get the Label value use this
Label ID = dgvrow.Cells[6].FindControl("lblid") as Label; //if lblid is label name and it is in 6th position if (ID != null) int id = Convert.ToInt32(ID.Text);
and use thisidvalue for further progress.
thanks
这篇关于如何隐藏gridview中的隐藏字段列。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!