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

S

Santosh

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.
 
W

Winista

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.
 
S

Santosh

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

Santosh.
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top