Repeater控件显示列自动换行方法

前台

<asp:Repeater ID="rpCommonSub" runat="server" OnItemDataBound="rpCommonSub_ItemDataBound">
    <ItemTemplate>
        <td width="22" height="27">
            <img src="../images/ico02.gif" width="12" height="12" />
        </td>
        <td width="138" class="font" align="left">
            <a href="#" class="three" id="subs" runat="server"></a>
        </td>
        <span style="color: #ff0000">
            <asp:Literal ID="ltrlBr" runat="server"></asp:Literal>
        </span>
    </ItemTemplate>
</asp:Repeater>

 

后台

   /// <summary>
        /// 行绑定事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void rpCommonSub_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            RepeaterItem rptItem = e.Item;
            DataRow dtRow = (rptItem.DataItem as DataRowView).Row;
            int id = int.Parse(dtRow["atID"].ToString());
            string sectionName = dtRow["atName"].ToString();

            // 动态设置相关栏目超链接
            HtmlAnchor sectionLnk = rptItem.FindControl("subs") as HtmlAnchor;
            sectionLnk.Title = sectionName;
            sectionLnk.HRef = "workCommSubList.aspx?cw_id=" + id + "&sj_dir=workHall&pardir=workHall";
            DataSet ds = _AttrdictBO.getXZSPatNameByAtID(ThemeID);
            if (sectionName == ds.Tables[0].Rows[0]["atName"].ToString())
            {
                sectionLnk.InnerText = sectionName;
                sectionLnk.Attributes["style"] = "font-weight:bold;";//如果有传过来的id查询出来的分类名称和所查询所有的名称里边的匹配,加粗事项名称
            }
            else
            {
                sectionLnk.InnerText = sectionName;
            }

            // repeater嵌套使用,内层repeater每次初始置1后操作
            if (rptItem.ItemIndex == 0)
            {
                tdIndex = 1;
            }
            if (tdIndex % 3 == 0)
            {
                Literal ltrlBr = rptItem.FindControl("ltrlBr") as Literal;
                ltrlBr.Text = "</tr><tr>";
            }
            tdIndex++;

        }

posted @ 2013-08-20 11:23  Amir_Blogs  阅读(589)  评论(0编辑  收藏  举报