在webformgrid中显示强类型绑定数据数据源
本文关键字:绑定 数据 数据源 强类型 显示 webformgrid | 更新日期: 2023-09-27 18:13:24
我在ASP工作。NET 3.5和我试图在网格中显示数据。我有一个模型类,数据存储为强类型列表。我有一个Repeater控件显示所有的数据,但原因是不工作在网格
模型类
public class RolesModel
{
public RolesModel() { }
public long RoleID { get; set; }
public string Title { get; set; }
public string Description { get; set; }
public DateTime CreatedDate { get; set; }
}
aspx.cs类protected void Page_Load(object sender, EventArgs e)
{
if(!Page.IsPostBack)
{
List<RolesModel> roleList = new List<RolesModel>();
roleList = RoleDefinationRelay.GetAllRoles(null);
rptRoles.DataSource = roleList;
rptRoles.DataBind();
}
}
ASP:Repeater (is working!)
<asp:Repeater ID="rptRoles" runat="server">
<HeaderTemplate>
<table class="tableStyle1">
<tr>
<td>Role ID</td>
<td>Title</td>
<td>Description</td>
<td>Created Date</td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td><%#Eval("RoleID")%></td>
<td><%#Eval("Title")%></td>
<td><%#Eval("Description")%></td>
<td><%#Eval("CreatedDate")%></td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
需要使网格工作在这里,但不工作
<cc0:Grid ID="ItemList" runat="server" FolderStyle="~/Styles/Grid" AutoGenerateColumns="true"
Width="100%" PageSizeOptions="5,10,20,50,100,-1" AllowFiltering="true" FilterType="ProgrammaticOnly"
AllowAddingRecords="false" DataSourceID="rptRoles">
<Columns>
<cc0:Column DataField="RoleID" HeaderText="Role ID" Visible="true" />
<cc0:Column DataField="Title" HeaderText="Title" Width="150" />
<cc0:Column DataField="Description" HeaderText="Description" />
<cc0:Column DataField="CreatedDate" HeaderText="Created Date" Width="150" />
</Columns>
</cc0:Grid>
在你的代码后面试试;
protected void Page_Load(object sender, EventArgs e)
{
if(!Page.IsPostBack)
{
List<RolesModel> roleList = new List<RolesModel>();
roleList = RoleDefinationRelay.GetAllRoles(null);
ItemList.DataSource = roleList;
ItemList.DataBind();
}
}
并从您的网格标记中删除DataSourceID