How to bind data from database to the header template of Datagrid

Discussion in 'ASP .Net' started by Santosh, Jun 8, 2006.

  1. Santosh

    Santosh Guest

    Dear all i want to bind data to datagrid header template i am wrtting
    follwing code it is displaying data with in item template not but it is
    display data in header template


    <asp:DataGrid ID="datagrid" Runat="server" ShowHeader="True">
    <Columns>
    <asp:TemplateColumn>
    <HeaderTemplate>
    <asp:Label ID="Label1" Runat="server" Text='<%#
    DataBinder.Eval(Container, "Dataitem.StateNo") %>'>
    </asp:Label></HeaderTemplate>
    <ItemTemplate>
    <asp:Label ID="Label3" Runat="server" Text='<%#
    DataBinder.Eval(Container, "Dataitem.StateNo") %>'></asp:Label>
    </ItemTemplate>
    </asp:TemplateColumn>
    <asp:TemplateColumn>
    <HeaderTemplate>
    <asp:Label ID="Label2" Runat="server" Text='<%#
    DataBinder.Eval(Container, "Dataitem.StateDesc") %>'>
    </asp:Label>
    </HeaderTemplate>
    <ItemTemplate>
    <asp:Label ID="Label4" Runat="server" Text='<%#
    DataBinder.Eval(Container, "Dataitem.StateDesc") %>'>
    </asp:Label>
    </ItemTemplate>
    </asp:TemplateColumn>
    </Columns>
    </asp:DataGrid>

    private void Page_Load(object sender, System.EventArgs e)
    {
    // Put user code to initialize the page here

    DataView dv = new DataView();
    dv.Table=objstate.GetAllRecords("","");
    datagrid.DataSource=dv;
    datagrid.DataBind();

    }


    please tell me the problem in this code

    Regards
    Santosh.
    Santosh, Jun 8, 2006
    #1
    1. Advertising

  2. Santosh

    Winista Guest

    DataItem is for "ITEMS" and not for Header. You are trying to put
    information in header which is going to be available when data items start
    filling. Even if it works do you think header should be changing for every
    single record in your data.

    "Santosh" <> wrote in message
    news:...
    > Dear all i want to bind data to datagrid header template i am wrtting
    > follwing code it is displaying data with in item template not but it is
    > display data in header template
    >
    >
    > <asp:DataGrid ID="datagrid" Runat="server" ShowHeader="True">
    > <Columns>
    > <asp:TemplateColumn>
    > <HeaderTemplate>
    > <asp:Label ID="Label1" Runat="server" Text='<%#
    > DataBinder.Eval(Container, "Dataitem.StateNo") %>'>
    > </asp:Label></HeaderTemplate>
    > <ItemTemplate>
    > <asp:Label ID="Label3" Runat="server" Text='<%#
    > DataBinder.Eval(Container, "Dataitem.StateNo") %>'></asp:Label>
    > </ItemTemplate>
    > </asp:TemplateColumn>
    > <asp:TemplateColumn>
    > <HeaderTemplate>
    > <asp:Label ID="Label2" Runat="server" Text='<%#
    > DataBinder.Eval(Container, "Dataitem.StateDesc") %>'>
    > </asp:Label>
    > </HeaderTemplate>
    > <ItemTemplate>
    > <asp:Label ID="Label4" Runat="server" Text='<%#
    > DataBinder.Eval(Container, "Dataitem.StateDesc") %>'>
    > </asp:Label>
    > </ItemTemplate>
    > </asp:TemplateColumn>
    > </Columns>
    > </asp:DataGrid>
    >
    > private void Page_Load(object sender, System.EventArgs e)
    > {
    > // Put user code to initialize the page here
    >
    > DataView dv = new DataView();
    > dv.Table=objstate.GetAllRecords("","");
    > datagrid.DataSource=dv;
    > datagrid.DataBind();
    >
    > }
    >
    >
    > please tell me the problem in this code
    >
    > Regards
    > Santosh.
    >
    Winista, Jun 8, 2006
    #2
    1. Advertising

  3. Santosh

    Santosh Guest

    So please tell me the solution behind them i want display records in to
    it.

    Santosh.
    Winista wrote:
    > DataItem is for "ITEMS" and not for Header. You are trying to put
    > information in header which is going to be available when data items start
    > filling. Even if it works do you think header should be changing for every
    > single record in your data.
    >
    > "Santosh" <> wrote in message
    > news:...
    > > Dear all i want to bind data to datagrid header template i am wrtting
    > > follwing code it is displaying data with in item template not but it is
    > > display data in header template
    > >
    > >
    > > <asp:DataGrid ID="datagrid" Runat="server" ShowHeader="True">
    > > <Columns>
    > > <asp:TemplateColumn>
    > > <HeaderTemplate>
    > > <asp:Label ID="Label1" Runat="server" Text='<%#
    > > DataBinder.Eval(Container, "Dataitem.StateNo") %>'>
    > > </asp:Label></HeaderTemplate>
    > > <ItemTemplate>
    > > <asp:Label ID="Label3" Runat="server" Text='<%#
    > > DataBinder.Eval(Container, "Dataitem.StateNo") %>'></asp:Label>
    > > </ItemTemplate>
    > > </asp:TemplateColumn>
    > > <asp:TemplateColumn>
    > > <HeaderTemplate>
    > > <asp:Label ID="Label2" Runat="server" Text='<%#
    > > DataBinder.Eval(Container, "Dataitem.StateDesc") %>'>
    > > </asp:Label>
    > > </HeaderTemplate>
    > > <ItemTemplate>
    > > <asp:Label ID="Label4" Runat="server" Text='<%#
    > > DataBinder.Eval(Container, "Dataitem.StateDesc") %>'>
    > > </asp:Label>
    > > </ItemTemplate>
    > > </asp:TemplateColumn>
    > > </Columns>
    > > </asp:DataGrid>
    > >
    > > private void Page_Load(object sender, System.EventArgs e)
    > > {
    > > // Put user code to initialize the page here
    > >
    > > DataView dv = new DataView();
    > > dv.Table=objstate.GetAllRecords("","");
    > > datagrid.DataSource=dv;
    > > datagrid.DataBind();
    > >
    > > }
    > >
    > >
    > > please tell me the problem in this code
    > >
    > > Regards
    > > Santosh.
    > >
    Santosh, Jun 9, 2006
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. mr2_93
    Replies:
    1
    Views:
    3,593
    mr2_93
    Oct 2, 2005
  2. Santosh
    Replies:
    0
    Views:
    726
    Santosh
    Aug 2, 2006
  3. mlt
    Replies:
    2
    Views:
    832
    Jean-Marc Bourguet
    Jan 31, 2009
  4. Jodi
    Replies:
    0
    Views:
    154
  5. UJ
    Replies:
    1
    Views:
    1,045
    Ken Cox [Microsoft MVP]
    Oct 3, 2006
Loading...

Share This Page