我有一个由可查询的数据源和模板列组成的网格。
<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();
因此,问题是状态字段(模板列)位于“描述”字段之前。但我希望首先显示描述。你可以帮我完成这个吗?
答案 0 :(得分: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;
}
}