• Repeater嵌套使用


    未完。。

    前台代码:

    <asp:Repeater ID="Repeater_Info" runat="server" OnItemDataBound="Repeater_Info_ItemDataBound">
    //OnItemDataBound是绑定后台,使后台的代码和repeater绑定
      <ItemTemplate>
    <tr>
    <td width="20" nowrap="nowrap">//nowrap:表单内容不换行
              <strong>内容1</strong>
    </td>
    <td align="left" nowrap="nowrap">
    <strong>内容2</strong>
    </td>
    </tr>
    <tr>
    <td colspan="2">
    <asp:Repeater ID="Content_List" runat="server">
    <ItemTemplate>
    <td nowrap="nowrap" runat="server" id="typeTd">//runat="server",服务器控件的使用,可以在后台调用id
                   </td>
    <td>
    <label for="<%#Eval("ContentID") %>">//绑定后台数据
    <%#Eval("Content") %>
    </label>//点击label上显示的后台的Content的内容,可以选中ContentID绑定的内容
    </td>
    </ItemTemplate>
    </asp:Repeater>
    </td>
    </tr>
    </ItemTemplate>
    </asp:Repeater>

    后台代码:

    protected void Repeater_Info_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
    //判断里层repeater处于外层repeater的哪个位置( AlternatingItemTemplate,FooterTemplate,HeaderTemplate,ItemTemplate,SeparatorTemplate)
    if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
    {
    Repeater rep
    = e.Item.FindControl("Content_List") as Repeater;//找到里层的repeater对象
    rep.ItemDataBound += new RepeaterItemEventHandler(rep_ItemDataBound);
    DataRowView rowv
    = (DataRowView)e.Item.DataItem;//找到分类Repeater关联的数据项
    int typeid = Convert.ToInt32(rowv["QuestionID"]); //获取填充子类的id
              //数据库的连接,数据的绑定
    DataTable dt
    = dsInfo.Tables[0];
    AQ.TypeID
    = (int)dt.Rows[0]["TypeID"];
    rep.DataSource
    = dsInfo.Tables[0];//数据绑定
    rep.DataBind();
    }
    }

    void rep_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
    if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
    {
    //找到里层的td对象
    HtmlTableCell td = e.Item.FindControl("typeTd") as HtmlTableCell;
    DataRowView rowv
    = (DataRowView) e.Item.DataItem ;
    if ((int)rowv["TypeID"] == 1)
    {

    td.InnerHtml = "<input type=\"radio\" id=\"" + rowv["ContentID"].ToString() + "\" name=\"" + rowv["QuestionID"].ToString() + "\" value=\"" + rowv["ContentID"].ToString() + "\"/>";
    }
    else if ((int)rowv["TypeID"] == 2)
    {

    td.InnerHtml = "<input type=\"checkbox\" id=\"" + rowv["ContentID"].ToString() + "\" name=\"" + rowv["QuestionID"].ToString() + "\" value=\"" + rowv["ContentID"].ToString() + "\"/>";
    }
    else
    {

    td.InnerHtml = "<input type=\"text\" id=\"" + rowv["ContentID"].ToString() + "\" name=\"" + rowv["QuestionID"].ToString() + "\" value=\"" + rowv["ContentID"].ToString() + "\"/>";
    }
    }
    }
  • 相关阅读:
    SVN_Clean up Error: Previous operation has not finished; run 'cleanup' if it was interrupted 。
    20220311T07:45:56.000Z中的T和Z分别表示什么
    Android Studio手动配置Gradle的方法
    fontvariantnumeric属性来实现数字的等宽
    修改mysql root 密码
    gitea 常用命令
    Oracle LOB字段
    kafka(java客户端)消费者取不到消息,生产者消息也没发送成功
    DIY 2.4G Expreless PWM 5通道迷你接收机
    吐槽:牛客网上的js编程笔试题
  • 原文地址:https://www.cnblogs.com/jianglan/p/2166727.html
Copyright © 2020-2023  润新知