0

我有一个由可查询数据源和模板列组成的网格。

       <telerik:RadGrid ID="rulesGrid" runat="server" AutoGenerateColumns="true">
      <MasterTableView>
      <Columns>
      <telerik:GridTemplateColumn HeaderText="Status" UniqueName="statusResult">
       </telerik:GridTemplateColumn>
       </Columns>
      </MasterTableView>

     </telerik:RadGrid>

并在 page_load

     var ruleset = (from s in (this.Page as BasePage).DbContext.ProductEventChecks
                       where s.Sequence!=0
                       orderby s.Sequence
                       select new
                       {
                           Description = s.Description
                       });

        rulesGrid.DataSource = ruleset;
        rulesGrid.DataBind();

所以,问题是状态字段(模板列)出现在描述字段之前。但我希望首先显示描述。你能帮我完成这个吗?

4

1 回答 1

2

请检查下面的代码片段。

.aspx

 <telerik:RadGrid ID="RadGrid1" runat="server" OnNeedDataSource="RadGrid1_NeedDataSource"
    AllowPaging="True" OnPreRender="RadGrid1_PreRender" 
    AutoGenerateColumns="true" oncolumncreated="RadGrid1_ColumnCreated">
    <PagerStyle AlwaysVisible="true" />
    <MasterTableView>

    </MasterTableView>
</telerik:RadGrid>

.aspx.cs

protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
    dynamic data = new[] {
            new { ID = 1, Name ="Name1"}
        };

    RadGrid1.DataSource = data;
}
protected void RadGrid1_ColumnCreated(object sender, GridColumnCreatedEventArgs e)
{
    if (e.Column.UniqueName == "ID")
    {
        e.Column.OrderIndex = 1;
    }
    else if (e.Column.UniqueName == "Name")
    {
        e.Column.OrderIndex = 0;
    }

}
于 2012-04-20T08:00:15.587 回答