Hiding columns in GridView control

Discussion in 'ASP .Net Web Controls' started by srinivas, Aug 2, 2006.

  1. srinivas

    srinivas Guest

    I have binded a dataset to a gridview control at run time.
    I'm fetching 5 columns from the database.
    But while displaying it on the screen i want to show only 3 columns.
    I tried with gridview.columns(i).visible property,but it did't work.

    Thanks in advance
    srinivas, Aug 2, 2006
    1. Advertisements

  2. srinivas

    puja Guest

    hi first of all, go to columns property of grid view and the checkbox called
    "autogenerate fields should not be ticked.

    if u see below example then although am fetching 5 columns in dataset, am
    displaying only 3 namely property address, sales person and date requested.

    hope this helps.

    <asp:GridView ID="grdContract" runat="server" AllowSorting="True"

    BorderColor="Silver" BorderStyle="Solid" BorderWidth="1px"
    DataKeyNames="File Number"

    EmptyDataText="No Contracts Found" Height="189px"

    OnRowCreated="HighlightRow" OnSorting="SortGrdContract" Width="100%"


    <asp:TemplateField HeaderText="Property Address" SortExpression="Property


    <asp:Label ID="lblPropertyAddress" runat="server" Text='<%#
    DataBinder.Eval(Container, "DataItem.Property Address") %>'>



    <ControlStyle Width="180px" />

    <ItemStyle HorizontalAlign="Left" />


    <asp:TemplateField HeaderText="Sales Person" SortExpression="Sales Person">


    <asp:Label ID="lblSalesPerson" runat="server" Text='<%#
    DataBinder.Eval(Container, "DataItem.Sales Person") %>'>



    <ControlStyle Width="120px" />


    <asp:TemplateField HeaderText="Date Requested" SortExpression="Date


    <asp:Label ID="lblDateRequested" runat="server" Text='<%#
    String.Format("{0:dd/MM/yy}", Convert.ToDateTime(DataBinder.Eval(Container,
    "DataItem.Date Requested")))%>'>




    puja, Aug 4, 2006
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.