zoukankan      html  css  js  c++  java
  • 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() + "\"/>";
    }
    }
    }
  • 相关阅读:
    修改VNC的分辨率
    How to use WinSCP with public key authentication
    CentOS-7-x86_64-DVD-1511.iso
    6.828
    Tampermonkey版Vimium
    servlet+jsp完成简单登录
    Servlet知识点小结
    HTTP基础知识点小结
    LeetCode 371两数之和
    LeetCode53 最大子序列问题
  • 原文地址:https://www.cnblogs.com/jianglan/p/2166727.html
Copyright © 2011-2022 走看看