About Gridview heading setting

Posted by Amritha444 under C# on 12/29/2010 | Points: 10 | Views : 1823 | Status : [Member] | Replies : 2
Hi all

My problem related with grid view heading settings
iam not binding datatable to gridview.instead binding each coloum after proper calculation everything working fine
my issue is how to give double heading.my code going on like this
DataTable dt = new DataTable();
DataTable dttype = objtype.GetGridRecords();
if (dttype.Rows.Count > 0)
{
for (int i = 0; i < dttype.Rows.Count; i++)
{
//* set colums of table by payroll types *//
dt.Columns.Add("B_"+dttype.Rows[i]["ShortName"].ToString());


}

}
binding row to it by another looping
in run time heading appears as

B_BP,B_DA,B_MRA....

i want a row above it by mergin all this named 'before LOP' just like below

' before LOP
B_BP,B_DA,B_MRA

which merges all the fields above items with B_..


Thanks in Advance




Responses

Posted by: Karthikanbarasan on: 1/5/2011 [Member] [Moderator] [Microsoft_MVP] [MVP] Silver | Points: 25

Up
0
Down
hi,

Do you need to have a header for the grid?

Thanks
Karthik
www.f5Debug.net

Amritha444, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Suresh.mekkattil on: 1/9/2011 [Member] Bronze | Points: 25

Up
0
Down
Hi,

You can do this by using repeater easly.

Step1:
Create a Repeater and in the <ItemTemplate> of its, create another repeater.

<asp:Repeater ID="Repeater1" runat="server">
<HeaderTemplate>
</HeaderTemplate>
<ItemTemplate>
<asp:Repeater ID="Repeater2" runat="server">
<ItemTemplate>
</ItemTemplate>
</asp:Repeater>
</ItemTemplate>
</asp:Repeater>



Note: you have to create a template and the write the binding code for the repeater


Step2:
Create another DataTable By loop through the dt.Columns till dt.Columns.Count. This is to be considered as your Headers.

Step3:
Then its time to bind the repeater.
Assign the your header datatable to the Repeater1.DataSource, and call the Repeater1.DataBind()

Step4:
You need to write some code for the Repeater1.ItemDataBound as follows:

protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
Repeater rptRecords = (Repeater)e.Item.FindControl("Repeater2");
if (rptRecords != null)
{
// do your Databinding here....
// rptRecords.DataSource=.......
// rptRecords.DataBind()
}
}


Thats all..

Please feel free to contact for any doubts.

-----
Suresh M

Amritha444, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response