
Hello
I am trying to bind the data to the RadGrid dynamically using NeedDataSource event.
My Columns and rows are to be created dynamically. For selecting Year in a particular table, I am creating column for years in the RadGrid. And for each cell of the Grid there is a label control to be added.
How can I do this, I have tried few ways but failed. Can you please guide?
Here is my code on NeedDataSource Event
if
(dsYears.Tables[0].Rows.Count > 0)
{
for (int i = 0; i < dsYears.Tables[0].Rows.Count; i++)
{
if (Convert.ToInt32(dsYears.Tables[0].Rows[i]["Fyear"]) > 0)
{
if (CurrentYear.ToString() != dsYears.Tables[0].Rows[i]["Fyear"].ToString())
{
TempColumn =
new GridTemplateColumn();
lblYear =
new Label();
lblYear.ID =
"lbl_" + dsYears.Tables[0].Rows[i]["Fyear"].ToString();
//lblYear.Text = dsYears.Tables[0].Rows[i]["Fyear"].ToString();
TempColumn.ItemTemplate.Equals(lblYear);
//TempColumn.ItemTemplate.InstantiateIn(lblYear);
TempColumn.HeaderText = dsYears.Tables[0].Rows[i][
"Fyear"].ToString();
RadGrid1.MasterTableView.Columns.Add(TempColumn);
}
}
}
}
Please guide me if I am using wrong event for this tasks or doing anything wrong..
Thank you
Shailendrasinh
<telerik:RadTreeView ID="RadTreeView1" runat="server" DataSourceID="SqlDataSource1" DataTextField="DESCRIPTION" DataValueField="CODE"></telerik:RadTreeView>
Using the above code, I got the output as
o Scanner ( description)
o Printer ( description)
o Laptop ( description)
o Cute FTp ( description)
o Logmein ( description
Below is sql select query
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:EsteeConnectionString %>"
SelectCommand="SELECT [CODE], [DESCRIPTION],[MAINCATEGORY] FROM [BRANDMASTER]"></asp:SqlDataSource>
Ø Hardware ( maincategory )
o Scanner ( description)
o Printer ( description)
o Laptop ( description)
Ø Software (maincategory)
o Cute FTp ( description)
o Logmein ( description)