【问题标题】:loading header for infragistics grid基础设施网格的加载标题
【发布时间】:2013-05-07 22:04:09
【问题描述】:

我有一个基础架构网格,其中填充了选定的下拉列表。存储的过程将列名和数据带入包含 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();



    }

【问题讨论】:

  • 第一个结果集是否包含单行并且其中的数据与第二个结果集中的列的顺序相同?

标签: c# asp.net .net infragistics webdatagrid


【解决方案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 命令之后添加此代码。它将遍历第一个表,将第一行中的数据分配给网格的列标题标题。

【讨论】:

  • 谢谢 Yuriy Galanter,firstResult 是一个列名由 | 分隔的对象怎么能循环通过呢?收到错误说无法将对象转换为字符串
  • 如果是单个值,则需要使用.ToString() 方法将其转换为String,然后使用String 的.Split("|") 方法将其拆分为字符串数组。之后,您将遍历该数组,对上面的代码进行类似的分配。
猜你喜欢
  • 1970-01-01
  • 2013-03-07
  • 1970-01-01
  • 1970-01-01
  • 2019-01-29
  • 1970-01-01
  • 1970-01-01
  • 2011-03-29
  • 2016-06-16
相关资源
最近更新 更多