当前位置:编程学习 > C#/ASP.NET >>

写4层的层级,用了4个repeater一个套一个,一上来加载很慢,repeater只能页面一加载的时候绑定数据吗。

js里能给repeater绑定吗,或者大家有什么好用的方法或树形吗,100分求~~ --------------------编程问答-------------------- http://fineui.com/demo/#/demo/grid/grid_simulate_tree.aspx

你要找这个? --------------------编程问答-------------------- repeater里面不能不能在套repeater,你要做级联,可以在后置代码里创建一个全局变量,然后在后置代码里查询循环把层级在前台页面带代码累加成一串字符串赋值给全局变量,然后前台<%=全局变量%>调用就可以了 --------------------编程问答--------------------
引用 2 楼 jss122414092 的回复:
repeater里面不能不能在套repeater,你要做级联,可以在后置代码里创建一个全局变量,然后在后置代码里查询循环把层级在前台页面带代码累加成一串字符串赋值给全局变量,然后前台<%=全局变量%>调用就可以了

这个可以给第二级赋值 可是第三级呢 --------------------编程问答-------------------- 你可以在加载是只绑定最外层的repeater,
然后在最外层的ItemDataBound中绑定第二层repeater,
同理,依次绑定一下的;
如果这样觉得加载页面是时压力大的话,可以考虑在外层的列中加个小按钮,然后点击的时候在ItemCommand中再去绑定第二层的数据,这样在加载时就等于说只加载了一个repeater的绑定 --------------------编程问答--------------------
引用 4 楼 purple_snow 的回复:
你可以在加载是只绑定最外层的repeater,
然后在最外层的ItemDataBound中绑定第二层repeater,
同理,依次绑定一下的;
如果这样觉得加载页面是时压力大的话,可以考虑在外层的列中加个小按钮,然后点击的时候在ItemCommand中再去绑定第二层的数据,这样在加载时就等于说只加载了一个repeater的绑定

看这个链接,无限极分类,一样的道理,无限递归http://bbs.csdn.net/topics/390462798?page=1不懂可以问我 --------------------编程问答-------------------- 如图第一列中实现了递归分类


protected StringBuilder str = new StringBuilder();
#region 绑定一级栏目内容
public void BindTableData()
{
   DataSet ds = DBsql.Query("select * from VM_SYS_Menu where MenuRecursive = 0 order by 

MenuOrder,MenuID desc");
                str = new StringBuilder();
                if (ds.Tables[0].Rows.Count > 0)
                {
                    str.Append("<table id=\"idData\" cellpadding=\"0\" cellspacing=\"0\" 

style=\"text-align:center;width:890px;font-size:12px;\">");
                    str.Append("<tr>");
                    str.Append("<td colspan=\"6\"><h5>栏目管理</h5>");
                    str.Append("<a href=\"AddMenu.aspx?type=firstMenu\" class=\"lb\">[添加

主栏目]</a></td>");
                    str.Append("</tr>");
                    str.Append("<tr onmousemove=\"style.background='#f5f5f5'\" 

onmouseout=\"style.background=''\" style=\"font-size:13px; color:black;\">");
                    str.Append("<td width=\"160\" style=\"text-align:left\"><strong>栏目名

称</strong></td>");
                    str.Append("<td width=\"80\" style=\"text-align:center\"><strong>栏目类

型</strong></td>");
                    str.Append("<td width=\"80\" style=\"text-align:center\"><strong>应用模

块</strong></td>");
                    str.Append("<td width=\"60\" style=\"text-align:center\"><strong>状

态</strong></td>");
                    str.Append("<td width=\"80\" style=\"text-align:center\"><strong>排

序</strong></td>");
                    str.Append("<td width=\"220\" style=\"text-align:center\"><strong>操

作</strong></td>");
                    str.Append("</tr>");
                    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                    {
                        str.Append("<tr onmousemove=\"style.background='#f5f5f5'\" 

onmouseout=\"style.background=''\">");
                        //判断栏目级别
                        str.Append("<td width=\"160\" style=\"text-align:left\">→" + 

ds.Tables[0].Rows[i]["MenuName"].ToString() + "</a></td>");
                        string MenuClass = ds.Tables[0].Rows[i]["MenuClass"].ToString();
                        if (MenuClass == "0")
                        {
                            str.Append("<td width=\"80\" style=\"text-align:center\">主导航

</td>");
                        }
                        else if (MenuClass == "1")
                        {
                            str.Append("<td width=\"80\" 

style=\"text-align:center\"></td>");
                        }
                        str.Append("<td width=\"80\" style=\"text-align:center\">" + 

ds.Tables[0].Rows[i]["FunctionName"].ToString() + "</td>");
                        string state = ds.Tables[0].Rows[i]["MenuState"].ToString();
                        if (state == "0")
                        {
                            str.Append("<td width=\"60\" style=\"text-align:center\"><a 

onclick=\"return confirm('确定要进行此操作吗?')\" href=\"UpdateMenu.aspx?type=Mstate&id=" + 

des.Encrypt(ds.Tables[0].Rows[i]["MenuID"].ToString()) + "\">正常</a></td>");
                        }
                        else if (state == "1")
                        {
                            str.Append("<td width=\"60\" style=\"text-align:center\"><a 

style=\"color:blue;\" onclick=\"return confirm('确定要进行此操作吗?')\" 

href=\"UpdateMenu.aspx?type=Mstate&id=" + des.Encrypt(ds.Tables[0].Rows[i]

["MenuID"].ToString()) + "\">关闭</a></td>");
                        }
                        str.Append("<td width=\"80\" style=\"text-align:center\">");
                        str.Append("<a href=\"MenuInfo.aspx?id=" + 

des.Encrypt(ds.Tables[0].Rows[i]["MenuID"].ToString()) + "\"\"><input maxlength=\"8\" 

value=\"" + ds.Tables[0].Rows[i]["MenuOrder"].ToString() + "\" 

onkeyup=\"this.value=this.value.replace(/\\D/g,'')\" name=\"SortOrder\" 

onfocus=\"setFocus()\" onblur=\"getNum(this.value+'," + ds.Tables[0].Rows[i]

["MenuID"].ToString() + "')\" id=\"SortOrder" + ds.Tables[0].Rows[i]["MenuID"].ToString() + 

"\" type=\"text\" title=\"输入数字后点击空白处进行保存\" style=\"width:60px\"/></a>");
                        str.Append("</td>");
                        str.Append("<td width=\"220\" style=\"text-align:center\">");
                        str.Append("<img src=\"../../images/LoginImg/add_update.png\"; 

alt=\"\" style=\"width: 15px; height: 15px;\" /><a href=\"UpdateMenu.aspx?type=edit&id=" + 

des.Encrypt(ds.Tables[0].Rows[i]["MenuID"].ToString()) + "\">[修改]</a>  ");
                        str.Append("<img src=\"../../images/LoginImg/Delete.png\"; alt=\"\" 

style=\"width: 15px; height: 15px;\" /><a href=\"UpdateMenu.aspx?type=delete&id=" + 

des.Encrypt(ds.Tables[0].Rows[i]["MenuID"].ToString()) + "\" OnClientClick=\"return 

confirm('确定要删除吗?')\">[删除]</a>  ");
                        str.Append("<img src=\"../../images/LoginImg/add_update.png\"; 

alt=\"\" style=\"width: 15px; height: 15px;\" /><a href=\"AddMenu.aspx?type=SecondMenu&id=" 

+ des.Encrypt(ds.Tables[0].Rows[i]["MenuID"].ToString()) + "\">[添加子栏目]</a>");
                        str.Append("</td>");
                        str.Append("</tr>");
                        //调用查询子栏目的方法
                        selectChildNode1(ds.Tables[0].Rows[i]["MenuID"].ToString(), 

"  ");
                    }
                    str.Append("</table>");
                }
}
#endregion
#region 查询子栏目
    public void selectChildNode1(string menuID, string sj)
    {
        DataSet ds = DBsql.Query("select * from VM_SYS_Menu where MenuRecursive=" + 

menuID);
        if (ds.Tables[0].Rows.Count > 0)
        {
            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                str.Append("<tr onmousemove=\"style.background='#f5f5f5'\" 

onmouseout=\"style.background=''\">");
                str.Append("<td width=\"160\" style=\"text-align:left\">" + sj + "→" + 

ds.Tables[0].Rows[i]["MenuName"].ToString() + "</a></td>");
                string MenuClass = ds.Tables[0].Rows[i]["MenuClass"].ToString();
                if (MenuClass == "0")
                {
                    str.Append("<td width=\"80\" style=\"text-align:center\">主导航</td>");
                }
                else if (MenuClass == "1")
                {
                    str.Append("<td width=\"80\" style=\"text-align:center\"></td>");
                }
                else if (MenuClass == "2")
                {
                    str.Append("<td width=\"80\" style=\"text-align:center\"></td>");
                }
                str.Append("<td width=\"80\" style=\"text-align:center\">" + 

ds.Tables[0].Rows[i]["FunctionName"].ToString() + "</td>");
                string state = ds.Tables[0].Rows[i]["MenuState"].ToString();
                if (state == "0")
                {
                    str.Append("<td width=\"60\"style=\"text-align:center\"><a 

onclick=\"return confirm('确定要进行此操作吗?')\" href=\"UpdateMenu.aspx?type=Mstate&id=" + 

des.Encrypt(ds.Tables[0].Rows[i]["MenuID"].ToString()) + "\">正常</a></td>");
                }
                else if (state == "1")
                {
                    str.Append("<td width=\"60\"style=\"text-align:center\"><a 

style=\"color:blue;\" onclick=\"return confirm('确定要进行此操作吗?')\" 

href=\"UpdateMenu.aspx?type=Mstate&id=" + des.Encrypt(ds.Tables[0].Rows[i]

["MenuID"].ToString()) + "\">关闭</a></td>");
                }
                str.Append("<td width=\"80\" style=\"text-align:center\">");
                str.Append("<a href=\"MenuInfo.aspx?id=" + 

des.Encrypt(ds.Tables[0].Rows[i]["MenuID"].ToString()) + "\"\"><input maxlength=\"8\" 

value=\"" + ds.Tables[0].Rows[i]["MenuOrder"].ToString() + "\" 

onkeyup=\"this.value=this.value.replace(/\\D/g,'')\" name=\"SortOrder\" 

onfocus=\"setFocus()\" onblur=\"getNum(this.value+'," + ds.Tables[0].Rows[i]

["MenuID"].ToString() + "')\" id=\"SortOrder" + ds.Tables[0].Rows[i]["MenuID"].ToString() + 

"\" type=\"text\" title=\"输入数字后点击空白处进行保存\" style=\"width:60px\"/></a>");

                str.Append("</td>");
                str.Append("<td width=\"220\" style=\"text-align:center\">");
                str.Append("<img src=\"../../images/LoginImg/add_update.png\"; alt=\"\" 

style=\"width: 15px; height: 15px;\" /><a href=\"UpdateMenu.aspx?type=edit&id=" + 

des.Encrypt(ds.Tables[0].Rows[i]["MenuID"].ToString()) + "\">[修改]</a>  ");
                str.Append("<img src=\"../../images/LoginImg/Delete.png\"; alt=\"\" 

style=\"width: 15px; height: 15px;\" /><a href=\"UpdateMenu.aspx?type=delete&id=" + 

des.Encrypt(ds.Tables[0].Rows[i]["MenuID"].ToString()) + "\" OnClientClick=\"return 

confirm('确定要删除吗?')\">[删除]</a>  ");
                str.Append("<img src=\"../../images/LoginImg/add_update.png\"; alt=\"\" 

style=\"width: 15px; height: 15px;\" /><a href=\"AddMenu.aspx?type=SecondMenu&id=" + 

des.Encrypt(ds.Tables[0].Rows[i]["MenuID"].ToString()) + "\">[添加子栏目]</a>");
                str.Append("</td>");
                str.Append("</tr>");
                //调用查询子栏目的子栏目方法(递归)
                selectChildNode(ds.Tables[0].Rows[i]["MenuID"].ToString(), sj + 

"  ");
            }
        }
    }
    #endregion
//前台页面
<body>
  <form id="form1" runat="server">
    <div>
        <%-- 绑定栏目信息 --%>
        <%= str.ToString() %>
    </div>
</body>
--------------------编程问答-------------------- repeater嵌套非常消耗资源的,但是有时候又必须那么做,具体代码忘记丢哪了 打个比方来说,现在有4个repeater。在repeater1的行绑定(还是行创建事件里面,我忘记了)可以找到repeater2然后给repeater2绑定数据。同理在repeater2的事件里面找到repeater3,一次类推
--------------------编程问答-------------------- 套那么多层,服务器解析起来还费力半天,前台的viewstate还大把大把的,看着都类的慌,不要老想着拖控件,你要打破它的束缚。
这种嵌套一方面是你设计的问题,一方面是对js和html的使用不够灵活 --------------------编程问答-------------------- 用6楼的方法已经实现了。 --------------------编程问答--------------------
引用 6 楼 lijingye0911 的回复:
如图第一列中实现了递归分类


protected StringBuilder str = new StringBuilder();
#region 绑定一级栏目内容
public void BindTableData()
{
   DataSet ds = DBsql.Query("select * from VM_SYS_Menu where MenuRecursive = 0 order by 

MenuOrder,MenuID desc");
                str = new StringBuilder();
                if (ds.Tables[0].Rows.Count > 0)
                {
                    str.Append("<table id=\"idData\" cellpadding=\"0\" cellspacing=\"0\" 

style=\"text-align:center;width:890px;font-size:12px;\">");
                    str.Append("<tr>");
                    str.Append("<td colspan=\"6\"><h5>栏目管理</h5>");
                    str.Append("<a href=\"AddMenu.aspx?type=firstMenu\" class=\"lb\">[添加

主栏目]</a></td>");
                    str.Append("</tr>");
                    str.Append("<tr onmousemove=\"style.background='#f5f5f5'\" 

onmouseout=\"style.background=''\" style=\"font-size:13px; color:black;\">");
                    str.Append("<td width=\"160\" style=\"text-align:left\"><strong>栏目名

称</strong></td>");
                    str.Append("<td width=\"80\" style=\"text-align:center\"><strong>栏目类

型</strong></td>");
                    str.Append("<td width=\"80\" style=\"text-align:center\"><strong>应用模

块</strong></td>");
                    str.Append("<td width=\"60\" style=\"text-align:center\"><strong>状

态</strong></td>");
                    str.Append("<td width=\"80\" style=\"text-align:center\"><strong>排

序</strong></td>");
                    str.Append("<td width=\"220\" style=\"text-align:center\"><strong>操

作</strong></td>");
                    str.Append("</tr>");
                    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                    {
                        str.Append("<tr onmousemove=\"style.background='#f5f5f5'\" 

onmouseout=\"style.background=''\">");
                        //判断栏目级别
                        str.Append("<td width=\"160\" style=\"text-align:left\">→" + 

ds.Tables[0].Rows[i]["MenuName"].ToString() + "</a></td>");
                        string MenuClass = ds.Tables[0].Rows[i]["MenuClass"].ToString();
                        if (MenuClass == "0")
                        {
                            str.Append("<td width=\"80\" style=\"text-align:center\">主导航

</td>");
                        }
                        else if (MenuClass == "1")
                        {
                            str.Append("<td width=\"80\" 

style=\"text-align:center\"></td>");
                        }
                        str.Append("<td width=\"80\" style=\"text-align:center\">" + 

ds.Tables[0].Rows[i]["FunctionName"].ToString() + "</td>");
                        string state = ds.Tables[0].Rows[i]["MenuState"].ToString();
                        if (state == "0")
                        {
                            str.Append("<td width=\"60\" style=\"text-align:center\"><a 

onclick=\"return confirm('确定要进行此操作吗?')\" href=\"UpdateMenu.aspx?type=Mstate&id=" + 

des.Encrypt(ds.Tables[0].Rows[i]["MenuID"].ToString()) + "\">正常</a></td>");
                        }
                        else if (state == "1")
                        {
                            str.Append("<td width=\"60\" style=\"text-align:center\"><a 

style=\"color:blue;\" onclick=\"return confirm('确定要进行此操作吗?')\" 

href=\"UpdateMenu.aspx?type=Mstate&id=" + des.Encrypt(ds.Tables[0].Rows[i]

["MenuID"].ToString()) + "\">关闭</a></td>");
                        }
                        str.Append("<td width=\"80\" style=\"text-align:center\">");
                        str.Append("<a href=\"MenuInfo.aspx?id=" + 

des.Encrypt(ds.Tables[0].Rows[i]["MenuID"].ToString()) + "\"\"><input maxlength=\"8\" 

value=\"" + ds.Tables[0].Rows[i]["MenuOrder"].ToString() + "\" 

onkeyup=\"this.value=this.value.replace(/\\D/g,'')\" name=\"SortOrder\" 

onfocus=\"setFocus()\" onblur=\"getNum(this.value+'," + ds.Tables[0].Rows[i]

["MenuID"].ToString() + "')\" id=\"SortOrder" + ds.Tables[0].Rows[i]["MenuID"].ToString() + 

"\" type=\"text\" title=\"输入数字后点击空白处进行保存\" style=\"width:60px\"/></a>");
                        str.Append("</td>");
                        str.Append("<td width=\"220\" style=\"text-align:center\">");
                        str.Append("<img src=\"../../images/LoginImg/add_update.png\"; 

alt=\"\" style=\"width: 15px; height: 15px;\" /><a href=\"UpdateMenu.aspx?type=edit&id=" + 

des.Encrypt(ds.Tables[0].Rows[i]["MenuID"].ToString()) + "\">[修改]</a>  ");
                        str.Append("<img src=\"../../images/LoginImg/Delete.png\"; alt=\"\" 

style=\"width: 15px; height: 15px;\" /><a href=\"UpdateMenu.aspx?type=delete&id=" + 

des.Encrypt(ds.Tables[0].Rows[i]["MenuID"].ToString()) + "\" OnClientClick=\"return 

confirm('确定要删除吗?')\">[删除]</a>  ");
                        str.Append("<img src=\"../../images/LoginImg/add_update.png\"; 

alt=\"\" style=\"width: 15px; height: 15px;\" /><a href=\"AddMenu.aspx?type=SecondMenu&id=" 

+ des.Encrypt(ds.Tables[0].Rows[i]["MenuID"].ToString()) + "\">[添加子栏目]</a>");
                        str.Append("</td>");
                        str.Append("</tr>");
                        //调用查询子栏目的方法
                        selectChildNode1(ds.Tables[0].Rows[i]["MenuID"].ToString(), 

"  ");
                    }
                    str.Append("</table>");
                }
}
#endregion
#region 查询子栏目
    public void selectChildNode1(string menuID, string sj)
    {
        DataSet ds = DBsql.Query("select * from VM_SYS_Menu where MenuRecursive=" + 

menuID);
        if (ds.Tables[0].Rows.Count > 0)
        {
            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                str.Append("<tr onmousemove=\"style.background='#f5f5f5'\" 

onmouseout=\"style.background=''\">");
                str.Append("<td width=\"160\" style=\"text-align:left\">" + sj + "→" + 

ds.Tables[0].Rows[i]["MenuName"].ToString() + "</a></td>");
                string MenuClass = ds.Tables[0].Rows[i]["MenuClass"].ToString();
                if (MenuClass == "0")
                {
                    str.Append("<td width=\"80\" style=\"text-align:center\">主导航</td>");
                }
                else if (MenuClass == "1")
                {
                    str.Append("<td width=\"80\" style=\"text-align:center\"></td>");
                }
                else if (MenuClass == "2")
                {
                    str.Append("<td width=\"80\" style=\"text-align:center\"></td>");
                }
                str.Append("<td width=\"80\" style=\"text-align:center\">" + 

ds.Tables[0].Rows[i]["FunctionName"].ToString() + "</td>");
                string state = ds.Tables[0].Rows[i]["MenuState"].ToString();
                if (state == "0")
                {
                    str.Append("<td width=\"60\"style=\"text-align:center\"><a 

onclick=\"return confirm('确定要进行此操作吗?')\" href=\"UpdateMenu.aspx?type=Mstate&id=" + 

des.Encrypt(ds.Tables[0].Rows[i]["MenuID"].ToString()) + "\">正常</a></td>");
                }
                else if (state == "1")
                {
                    str.Append("<td width=\"60\"style=\"text-align:center\"><a 

style=\"color:blue;\" onclick=\"return confirm('确定要进行此操作吗?')\" 

href=\"UpdateMenu.aspx?type=Mstate&id=" + des.Encrypt(ds.Tables[0].Rows[i]

["MenuID"].ToString()) + "\">关闭</a></td>");
                }
                str.Append("<td width=\"80\" style=\"text-align:center\">");
                str.Append("<a href=\"MenuInfo.aspx?id=" + 

des.Encrypt(ds.Tables[0].Rows[i]["MenuID"].ToString()) + "\"\"><input maxlength=\"8\" 

value=\"" + ds.Tables[0].Rows[i]["MenuOrder"].ToString() + "\" 

onkeyup=\"this.value=this.value.replace(/\\D/g,'')\" name=\"SortOrder\" 

onfocus=\"setFocus()\" onblur=\"getNum(this.value+'," + ds.Tables[0].Rows[i]

["MenuID"].ToString() + "')\" id=\"SortOrder" + ds.Tables[0].Rows[i]["MenuID"].ToString() + 

"\" type=\"text\" title=\"输入数字后点击空白处进行保存\" style=\"width:60px\"/></a>");

                str.Append("</td>");
                str.Append("<td width=\"220\" style=\"text-align:center\">");
                str.Append("<img src=\"../../images/LoginImg/add_update.png\"; alt=\"\" 

style=\"width: 15px; height: 15px;\" /><a href=\"UpdateMenu.aspx?type=edit&id=" + 

des.Encrypt(ds.Tables[0].Rows[i]["MenuID"].ToString()) + "\">[修改]</a>  ");
                str.Append("<img src=\"../../images/LoginImg/Delete.png\"; alt=\"\" 

style=\"width: 15px; height: 15px;\" /><a href=\"UpdateMenu.aspx?type=delete&id=" + 

des.Encrypt(ds.Tables[0].Rows[i]["MenuID"].ToString()) + "\" OnClientClick=\"return 

confirm('确定要删除吗?')\">[删除]</a>  ");
                str.Append("<img src=\"../../images/LoginImg/add_update.png\"; alt=\"\" 

style=\"width: 15px; height: 15px;\" /><a href=\"AddMenu.aspx?type=SecondMenu&id=" + 

des.Encrypt(ds.Tables[0].Rows[i]["MenuID"].ToString()) + "\">[添加子栏目]</a>");
                str.Append("</td>");
                str.Append("</tr>");
                //调用查询子栏目的子栏目方法(递归)
                selectChildNode(ds.Tables[0].Rows[i]["MenuID"].ToString(), sj + 

"  ");
            }
        }
    }
    #endregion
//前台页面
<body>
  <form id="form1" runat="server">
    <div>
        <%-- 绑定栏目信息 --%>
        <%= str.ToString() %>
    </div>
</body>

好乱的代码,它怎么维护呢?
补充:.NET技术 ,  ASP.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,