hiding column in a gridview

  • 9 years ago

    hi all,

    I am trying to access the value of a hidden column(gridview column) but it doesn't show. But when I unhide(Visible = True) the column it shows the value. My code:

    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)


    if (e.CommandName == "editstate")


    int index = Convert.ToInt32(e.CommandArgument);

    txt_state_cd.Text = GridView1.Rows[index].Cells[0].Text;

    txt_state_nm.Text = GridView1.Rows[index].Cells[1].Text;


     HTML Code:

    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" CellPadding="4" ForeColor="Black" GridLines="Horizontal" Width="175px" OnRowDeleting="GridView1_RowDeleting" OnRowCommand="GridView1_RowCommand">


    <asp:BoundField DataField="citystate_cd" ReadOnly="True" Visible="False" />

    <asp:BoundField DataField="citystate_nm" HeaderText="State Name" >

    <ItemStyle HorizontalAlign="Left" />


    <asp:ButtonField ButtonType="Image" ImageUrl="~/images/icon-edit.gif" Text="Edit" CommandName="editstate" />

    <asp:CommandField ButtonType="Image" DeleteImageUrl="~/images/icon-delete.gif" ShowDeleteButton="True" />


    <EditRowStyle BackColor="LightYellow" ForeColor="Gray" />

    <FooterStyle BackColor="#CCCC99" ForeColor="Black" />

    <SelectedRowStyle BackColor="#CC3333" Font-Bold="True" ForeColor="White" />

    <PagerStyle BackColor="White" ForeColor="Black" HorizontalAlign="Right" />

    <HeaderStyle BackColor="#333333" Font-Bold="True" ForeColor="White" />



    I have used a bound field for "citystate_cd" but I have set its Visible property to False(coz I don't want to show this column, but want to access its value). It does work. Whereas if I set the Visible property to True then it works. I want that it sahould be hidden as well as I should be able to access the value.




Post a reply

No one has replied yet! Why not be the first?

Sign in or Join us (it's free).


Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“The greatest performance improvement of all is when a system goes from not-working to working.” - John Ousterhout