Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/322.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在webForm网格中显示强类型绑定数据源_C#_Data Binding_Webforms_Datasource_Asp.net 3.5 - Fatal编程技术网

C# 在webForm网格中显示强类型绑定数据源

C# 在webForm网格中显示强类型绑定数据源,c#,data-binding,webforms,datasource,asp.net-3.5,C#,Data Binding,Webforms,Datasource,Asp.net 3.5,我在ASP.NET3.5中工作,我正在尝试在网格中显示数据。我有一个模型类,数据存储为强类型列表。我有一个中继器控件来显示所有的数据,但出于某种原因,它不能在网格中工作 模范班 aspx.cs类 受保护的无效页面加载(对象发送方,事件参数e) { 如果(!Page.IsPostBack) { List roleList=新列表(); roleList=RoleDefinitionRelay.GetAllRoles(null); rptRoles.DataSource=roleList; rptR

我在ASP.NET3.5中工作,我正在尝试在网格中显示数据。我有一个模型类,数据存储为强类型列表。我有一个中继器控件来显示所有的数据,但出于某种原因,它不能在网格中工作

模范班 aspx.cs类
受保护的无效页面加载(对象发送方,事件参数e)
{
如果(!Page.IsPostBack)
{
List roleList=新列表();
roleList=RoleDefinitionRelay.GetAllRoles(null);
rptRoles.DataSource=roleList;
rptRoles.DataBind();
}
}
ASP:中继器(正在工作!)

角色ID
标题
描述
创建日期
需要使网格在此工作,但不工作
在你的codebehind中试试这个

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();
    }
 }
受保护的无效页面加载(对象发送方,事件参数e)
{
如果(!Page.IsPostBack)
{
List roleList=新列表();
roleList=RoleDefinitionRelay.GetAllRoles(null);
ItemList.DataSource=roleList;
ItemList.DataBind();
}
}
并从网格标记中删除DataSourceID

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