0

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();



    }
Danko Valkov
  • 1,038
  • 8
  • 17
user2167089
  • 151
  • 6
  • 20

1 Answers1

1

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.

Yuriy Galanter
  • 38,833
  • 15
  • 69
  • 136
  • thank you Yuriy Galanter, The firstResult is an object with column names separated by | how can loop through it? getting error saying cannot convert object to string – user2167089 May 08 '13 at 15:56
  • If it's a single value, you need, using `.ToString()` method convert it to String, then using String's `.Split("|")` method split it into array of strings. After that you will loop thru that array doing similar assignment to the code above. – Yuriy Galanter May 08 '13 at 16:04