0

選択したドロップダウンが取り込まれるインフラジスティックス グリッドがあります。2 つのテーブルを含む結果セットに列名とデータをもたらすストアド プロシージャです。

ヘッダー情報を読み込むにはどうすればよいですか?

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

私のコードビハインドは

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



    }
4

1 に答える 1

1

テーブルの最初の行に列名が含まれ、実際のデータと同じ順序と数であると仮定すると、次TheFirstResultのようなことができます。

for (int I = 0; I < ds.Tables["TheFirstResult"].Columns.Count; I++) {
   this.EntityGrid.Columns[I].Header.Text = ds.Tables["TheFirstResult"].Rows[0][I];
}

コマンドの後にこのコードを追加しますDataBind。最初のテーブルをループして、最初の行のデータをグリッドの列ヘッダー キャプションに割り当てます。

于 2013-05-08T01:47:58.020 に答える