Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrieve data from visible false BoundField of Gridview

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

like image 877
Darshana Avatar asked Jul 14 '12 18:07

Darshana


3 Answers

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>
like image 192
COLD TOLD Avatar answered Sep 30 '22 15:09

COLD TOLD


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.

like image 21
Prashant Gupta Avatar answered Sep 30 '22 15:09

Prashant Gupta


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>
like image 27
Ruben de la Fuente Avatar answered Sep 30 '22 14:09

Ruben de la Fuente