• Repeater绑定Dictionary


    .aspx

    <asp:Repeater runat="server" ID="rptList" OnItemDataBound="rptList_ItemDataBound">
    <HeaderTemplate>
    <table id="mytable" border="1" cellpadding="0" cellspacing="0">
    </HeaderTemplate>
    <ItemTemplate>
    <tr>
    <td class="alt">
    <asp:Label runat="server" ID="lblKey" Text='<%#Eval("key")%>'></asp:Label>
    </td>
    <td>
    <asp:Repeater runat="server" ID="rptSubList" DataSource='<%#((System.Collections.Generic.KeyValuePair<string,System.Collections.Generic.List<dhySys.Entry.Info>>)Container.DataItem).Value %>'>
    <ItemTemplate>
    <table>
    <tr>
    <td style=" 65%">
    <%#Eval("Title") %>
    </td>
    <td>
    <asp:RadioButtonList runat="server" ID="rblScore" RepeatDirection="Horizontal" Width="250px">
    </asp:RadioButtonList>
    <asp:HiddenField runat="server" ID="hidScore" Value='<%#Eval("Score") %>'></asp:HiddenField>
    <%--<asp:HiddenField runat="server" ID="hidType" Value='<%# DataBinder.Eval(((RepeaterItem)Container.Parent.Parent).DataItem, "key")%>' /> --%>
    </td>
    </tr>
    </table>
    </ItemTemplate>
    </asp:Repeater>
    </td>
    </tr>
    </ItemTemplate>
    <FooterTemplate>

    .aspx.cs

    protected void BindRptList()
    {
    Dictionary
    <string, List<Info>> dicts = "数据源";
    rptList.DataSource
    = dicts;
    rptList.DataBind();
    }
    protected void rptList_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
    if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
    {
    Repeater rptSub
    = e.Item.FindControl("rptSubList") as Repeater;
    //动态生成RadioButtonList
    for (int i = 0; i < rptSub.Items.Count; i++)
    {
    HiddenField hidScore
    = (HiddenField)rptSub.Items[i].FindControl("hidScore");
    RadioButtonList rblScore
    = (RadioButtonList)rptSub.Items[i].FindControl("rblScore");
    int score = int.Parse(hidScore.Value);
    int[] ss = new int[score];
    for (int j = 1; j <= score; j++)
    {
    ss[j
    - 1] = j;
    }
    rblScore.DataSource
    = ss;
    rblScore.DataBind();
    }
    }
    }

  • 相关阅读:
    Asp.Net Winform 条形码系列之Code39 Code39 Of .Net BarCode Serial Blog
    .NET 中文星期几的简单实现方式
    C#使用SQLite数据库(asp.net/winform)
    .Net日期时间格式化输出大全 DateTime.ToString(?)
    C#使用HTTP头检测网络资源是否有效
    [转]C#(VB.NET)操作Windows自带的防火墙 之 添加/删除允许通过防火墙的例外程序
    华为C2800进入工程模式
    android webview 加载网页显示对话框
    SVN 与 VS2003
    VisualSVN1.7.7 序列号
  • 原文地址:https://www.cnblogs.com/gdjlc/p/2086876.html
Copyright © 2020-2023  润新知