i have a infragistics grid that gets populated with selected dropdown .the stored proc that brings column names and data in a result set with 2 tables.
how can i load header info?
<asp:DropDownList ID="DropDownList1" AutoPostBack="true" runat="server" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
<asp:ListItem>Select Entity</asp:ListItem>
</asp:DropDownList>
<asp:Label runat="server" ID="EntityName"></asp:Label>
<ig:WebScriptManager ID="WebScriptManager1" runat="server"></ig:WebScriptManager>
<ig:WebDataGrid ID="EntityGrid" runat="server" Width="100%" Height="50%" StyleSetName="Claymation" >
<Behaviors>
<ig:Sorting>
</ig:Sorting>
</Behaviors>
<ClientEvents Click="NavigateOnClick" />
</ig:WebDataGrid>
my code behind has
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
EntityName.Text = DropDownList1.SelectedItem.Text;
string entity = "t_" + DropDownList1.SelectedItem.Text;
String strConnString = ConfigurationManager.ConnectionStrings["LiveLeaseConnectionString"].ConnectionString;
SqlConnection con = new SqlConnection(strConnString);
SqlCommand cmd = new SqlCommand("p_DataList_ByRegardingObject", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@RegardingObjectName", entity);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
ds.Tables.Add("TheFirstResult");
ds.Tables.Add("TheSecondResult");
da.TableMappings.Add("Table", "TheFirstResult");
da.TableMappings.Add("Table1", "TheSecondResult");
da.Fill(ds);
this.EntityGrid.DataSource = ds.Tables["TheSecondResult"];
this.EntityGrid.DataBind();
}
Assuming that first row in TheFirstResult
table contains column names and they're in the same order and number as actual data, you can do something like this:
for (int I = 0; I < ds.Tables["TheFirstResult"].Columns.Count; I++) {
this.EntityGrid.Columns[I].Header.Text = ds.Tables["TheFirstResult"].Rows[0][I];
}
Add this code after DataBind
command. It will loop thru first table assigning data from its first row to column header captions of the grid.