I have this BoundField
in a GridView
<asp:BoundField DataField="ReportId" HeaderText="RId" Visible="false" />
But when I try to get text in that field, it returns empty.
protected void gvwReports_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "ViewSchedule")
{
int index = Convert.ToInt32(e.CommandArgument);
GridViewRow row = gvwReports.Rows[index];
string s = row.Cells[0].Text;
}
}
but, it returns a correct value if I change BoundField's
.Visible
property to true
try somethink like this using client side html to hide
<style type="text/css">
.hidden
{
display:none;
}
</style>
<asp:BoundField DataField="ReportId" HeaderText="RId" HeaderStyle-CssClass="hidden" >
</asp:BoundField>
Although it's an year old question (in fact exactly an year old), here's another workaround without using CssClass.
Just after the databind, set visibility of the desired column to false.
gridview1.databind()
gridview1.columns(i).Visibile = False
This will maintain data in viewstate but will not create markup for page.
the first solution works correctly, but it was necessary add HeaderStyle to hide the header of this column
<style type="text/css">
.hidden
{
display:none;
}
</style>
<asp:BoundField DataField="ReportId" HeaderText="RId" >
<ItemStyle CssClass="hidden"/>
<HeaderStyle CssClass="hidden"/>
</asp:BoundField>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With