DataList三层嵌套

18 篇文章 0 订阅

.cs文件


using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class admin_KindManage : System.Web.UI.Page
{
    SQLHelper sqlhelp = new SQLHelper();
    xhp_crb manage = new xhp_crb();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            list1bind();
        }
    }
    public void list1bind()
    {
        DataSet dslist = sqlhelp.getDataBySql("select qxid,qxmc from yh_qxb where qxfid=0 order by type");
        DataList1.DataSource = dslist.Tables[0].DefaultView;
        DataList1.DataBind();
    }
    protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            DataList dlt2 = (DataList)e.Item.FindControl("DataList2");
            DataSet list2 = sqlhelp.getDataBySql("select qxid,qxmc from yh_qxb where qxfid="+DataList1.DataKeys[e.Item.ItemIndex].ToString().Trim()+" order by type");
            dlt2.DataSource = list2.Tables[0].DefaultView;
            dlt2.DataBind();
            Image img1 =(Image) e.Item.FindControl("Image1");
            if (dlt2.Items.Count > 0)
                img1.ImageUrl = "../back/Images/1.gif";
            else
                img1.ImageUrl = "../back/Images/-.gif";
        }
    }
    protected void DataList1_DeleteCommand(object source, DataListCommandEventArgs e)
    {
        string id = DataList1.DataKeys[e.Item.ItemIndex].ToString();
        DataSet dm1 = sqlhelp.getDataBySql("select qxid from yh_qxb where qxfid="+id+"");
        for (int i = 0; i < dm1.Tables[0].Rows.Count; i++)
        {
            DataSet dm2 = sqlhelp.getDataBySql("select qxid from yh_qxb where qxfid='" + dm1.Tables[0].Rows[i][0].ToString() + "' order by type");
           if (dm2.Tables[0].Rows.Count > 0)
           {
               sqlhelp.updateBySql("delete from yh_qxb where qxid=" + dm2.Tables[0].Rows[0][0].ToString() + "");
           }
           sqlhelp.updateBySql("delete from yh_qxb where qxid="+dm1.Tables[0].Rows[i][0].ToString()+"");
          
        }
        bool del= sqlhelp.updateBySql("delete from yh_qxb where qxid='" + id + "'");
        if (del)
        {
            manage.script("删除成功!", this.Page);
        }
        list1bind();
    }
   
  
   protected void DataList2_DeleteCommand1(object source, DataListCommandEventArgs e)
    {
         HiddenField hid = (HiddenField)e.Item.FindControl("HiddenField1");
        string id =hid.Value.ToString().Trim();
        DataSet dn1 = sqlhelp.getDataBySql("select qxid from yh_qxb where qxfid='" + id + "' order by type");
        if (dn1.Tables[0].Rows.Count > 0)
        {
            for (int i = 0; i < dn1.Tables[0].Rows.Count; i++)
            {
                //DataSet dn2 = sqlhelp.getDataBySql("select qxid from yh_qxb where qxfid='"+dn1.Tables[0].Rows[i][0].ToString()+"'");
                sqlhelp.updateBySql("delete from yh_qxb where qxid=" + dn1.Tables[0].Rows[i][0].ToString() + "");
            }
        }
        bool del=sqlhelp.updateBySql("delete from yh_qxb where qxid="+id+"");
        if (del)
        {
            manage.script("删除成功!",this.Page);
        }
        list1bind();
    }
   protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
   {
       if (e.CommandName == "BigUp")
       {
           int Bukey = Convert.ToInt32(e.CommandArgument);
           DataTable dto = sqlhelp.getDataTableBySql("select type from yh_qxb where qxid='" + Bukey + "'");
           DataTable dt = sqlhelp.getDataTableBySql("select type from yh_qxb where qxfid in (select qxfid from yh_qxb where qxid='" + Bukey + "') order by type");
           int thisType = Convert.ToInt32(dto.Rows[0][0]);
           ArrayList list = new ArrayList();
           int index = 0; int otherType = 0;
           for (int i = 0; i < dt.Rows.Count; i++)
           {
               otherType = Convert.ToInt32(dt.Rows[i][0]);
               list.Add(otherType);
               if (Convert.ToInt32(dt.Rows[0][0]) == thisType)
               {
                   manage.script("已经是第一行!",this.Page);
                   return;
               }
               if (otherType == thisType)
               {
                   index = i;
               }
           }
           string sec = list[index-1].ToString();
           DataTable dtn = sqlhelp.getDataTableBySql("select qxid from yh_qxb where type='" + sec + "'");
           string secType = dtn.Rows[0][0].ToString();
           sqlhelp.updateBySql("update yh_qxb set type='" + sec + "' where qxid='" + Bukey + "'");
           sqlhelp.updateBySql("update yh_qxb set type='" + thisType + "' where qxid='" + secType + "'");
           list1bind();
       }
      
   }
   protected void DataList2_ItemCommand(object source, DataListCommandEventArgs e)
   {
       if (e.CommandName == "SmallUp")
       {
           int smallukey = Convert.ToInt32(e.CommandArgument);
           int SmallUp = Convert.ToInt32(e.CommandArgument);
           DataTable dto = sqlhelp.getDataTableBySql("select type from yh_qxb where qxid='" + SmallUp + "'");
           DataTable dt = sqlhelp.getDataTableBySql("select type from yh_qxb where qxfid in (select qxfid from yh_qxb where qxid='" + SmallUp + "') order by type");
           int thisType = Convert.ToInt32(dto.Rows[0][0]);
           ArrayList list = new ArrayList();
           int index = 0; int otherType = 0;
           for (int i = 0; i < dt.Rows.Count; i++)
           {
               otherType = Convert.ToInt32(dt.Rows[i][0]);
               list.Add(otherType);
               if (Convert.ToInt32(dt.Rows[0][0]) == thisType)
               {
                   manage.script("已经是第一行!", this.Page);
                   return;
               }
               if (otherType == thisType)
               {
                   index = i;
               }
           }
           string sec = list[index - 1].ToString();
           DataTable dtn = sqlhelp.getDataTableBySql("select qxid from yh_qxb where type='" + sec + "'");
           string secType = dtn.Rows[0][0].ToString();
           sqlhelp.updateBySql("update yh_qxb set type='" + sec + "' where qxid='" + SmallUp + "'");
           sqlhelp.updateBySql("update yh_qxb set type='" + thisType + "' where qxid='" + secType + "'");
           list1bind();
       }
      
   }
   protected void DataList2_ItemDataBound(object sender, DataListItemEventArgs e)
   {
       if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
       {
           DataList dlt2 = (DataList)sender;
           DataList dlt3 = (DataList)e.Item.FindControl("DataList3");
           Image img2 = (Image)e.Item.FindControl("Image2");
           string aa = dlt2.DataKeys[e.Item.ItemIndex].ToString().Trim();
           DataSet list3 = sqlhelp.getDataBySql("select qxid,qxmc from yh_qxb where qxfid=" + aa + " order by type");
           dlt3.DataSource = list3.Tables[0].DefaultView;
           dlt3.DataBind();
           if (dlt3.Items.Count > 0)
               img2.ImageUrl = "../back/Images/1.gif";
           else
               img2.ImageUrl = "../Back/Images/-.gif";
       }
   }
}

 

 

 

aspx文件


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="KindManage.aspx.cs" Inherits="admin_KindManage" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>菜单设置</title>
  
    <link href="../CSS/fontsmall.css" rel="stylesheet" type="text/css" />
    <script language="javascript">
        function infor()
        {
            if(confirm("确定要删除吗?"))
            {
                return true;
            }else return false;

        }
    </script>
</head>
<body>
    <form id="form1" runat="server" class="zlift">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
       
    <div style="text-align:left;">
    <div style="text-align:left; border-top-style: solid; border-right-style: solid; border-left-style: solid; border-top-width: 1px; border-right-width: 1px; border-left-width: 1px; border-top-color: #808080; border-right-color: #808080; border-left-color: #808080;" >
        <asp:DataList ID="DataList1" runat="server" Width="950px" DataKeyField="qxid" onitemdatabound="DataList1_ItemDataBound" ondeletecommand="DataList1_DeleteCommand" onitemcommand="DataList1_ItemCommand">
            <ItemTemplate>
                <table width="100%" border="0" style="border: 0px solid #FFFFFF; border-collapse:collapse;" cellpadding="0"
                    cellspacing="0">
                  <tr>
                    <td width="50%"
                          style="text-align:left; height:20px; border-bottom-style: solid; border-bottom-width: 1px; border-bottom-color: #808080; border-right-style: solid; border-right-width: 1px; border-right-color: #808080;">
                        <table width="100%" cellpadding="0" cellspacing="0">
                            <tr>
                                <td width="5%">
                                    <asp:Image ID="Image1" runat="server" />
                                </td>
                                <td width="95%" style="padding-top:3px"><%#DataBinder.Eval(Container.DataItem,"qxmc") %></td>
                            </tr>
                        </table>
                       
                    </td>
                    <td width="50%"
                          style="border-bottom-style: solid; border-bottom-width: 1px; border-bottom-color: #808080">
                        <table width="100%" cellpadding="0" cellspacing="0">
                            <tr>
                                <td style="width:20%" align="center">
                                    <asp:LinkButton ID="LinkButton1" runat="server" CommandName="abig1"
                                     PostBackUrl='<%#"../back/addbig_part.aspx?Bid="+Eval("qxid").ToString()+""%>' ForeColor="Black" Font-Underline="false">添加大栏目
                                     </asp:LinkButton>
                                </td>
                                <td style="width:20%" align="center">
                                    <asp:LinkButton ID="LinkButton2" runat="server" PostBackUrl='<%#"../back/AddBig_part.aspx?Sid="+Eval("qxid").ToString()+""%>' CommandName="asmall1"  ForeColor="Black" Font-Underline="false">添加子栏目</asp:LinkButton>
                                </td>
                                <td style="width:20%" align="center">
                                    <asp:LinkButton ID="LinkButton3" runat="server" CommandName="edit" PostBackUrl='<%#"../back/changekind.aspx?cid="+Eval("qxid").ToString()+""%>'  ForeColor="Black" Font-Underline="false">修改</asp:LinkButton>
                                </td>
                                <td style="width:20%" align="center">
                                    <asp:LinkButton ID="LinkButton4" runat="server" CommandName="delete"  ForeColor="Black" Font-Underline="false">删除</asp:LinkButton>
                                </td>
                                <td style="width:20%" align="center">
                                    <img src="../back/Images/013.gif" /><asp:LinkButton ID="LinkButton5" runat="server" ForeColor="Black" Font-Underline="false" CommandName="BigUp" CommandArgument='<%#Eval("qxid") %>'>上移</asp:LinkButton>
                                </td>
                               
                            </tr>
                        </table>
                    </td>
                  </tr>
                    <tr>
                        <td style="text-align:left; width: 100%;"
                            width="50%" colspan="2">
                            <asp:DataList ID="DataList2" runat="server" Width="100%" DataKeyField="qxid"
                                ondeletecommand="DataList2_DeleteCommand1"
                                onitemcommand="DataList2_ItemCommand"
                                onitemdatabound="DataList2_ItemDataBound">
                                <ItemTemplate>
                                    <table width="100%" border="0" style="border-collapse:collapse; border-bottom-style: solid; border-bottom-width: 1px; border-bottom-color: #808080;" cellpadding="0" cellspacing="0">
                                      <tr οnmοuseοver="this.style.backgroundColor='#9abbee'"   οnmοuseοut="this.style.backgroundColor='' ">
                                        <td width="50%" style="height:20px; padding-left:55px; border-right-color: #808080; border-right-width: 1px; border-right-style: solid;">
                                            <table width="100%" cellpadding="0" cellspacing="0">
                                                <tr>
                                                    <td width="5%">
                                                        <asp:Image ID="Image2" runat="server"  ImageUrl="" />
                                                    </td>
                                                    <td width="95%" style="padding-top:3px"><%#DataBinder.Eval(Container.DataItem,"qxmc") %>
                                                        <asp:HiddenField ID="HiddenField1" runat="server" Value='<%#DataBinder.Eval(Container.DataItem,"qxid") %>' />
                                                    </td>
                                                </tr>
                                            </table>
                                           
                                        </td>
                                        <td width="50%">
                                            <table width="100%" cellpadding="0" cellspacing="0">
                                                <tr>
                                                    <td style="width:20%" align="center"></td>
                                                    <td style="width:20%" align="center">
                                                        <asp:LinkButton ID="LinkButton8" runat="server" ForeColor="Black" Font-Underline="false" CommandName="addchild" PostBackUrl='<%#"../back/AddBig_part.aspx?two_Cid="+Eval("qxid").ToString()+""%>'>添加子栏目</asp:LinkButton>
                                                    </td>
                                                    <td style="width:20%" align="center">
                                                        <asp:LinkButton ID="LinkButton6" runat="server" PostBackUrl='<%#"../back/changekind.aspx?csid="+Eval("qxid").ToString()+""%>' CommandName="update2" ForeColor="Black" Font-Underline="false">修改</asp:LinkButton>
                                                    </td>
                                                    <td style="width:20%" align="center">
                                                        <asp:LinkButton ID="LinkButton7" runat="server" CommandName="delete" ForeColor="Black" Font-Underline="false" OnClientClick="infor()">删除</asp:LinkButton>
                                                    </td>
                                                   <td style="width:20%" align="center">
                                                        <%--<img src="Images/013.gif" /><asp:LinkButton ID="LinkButton5" runat="server" ForeColor="Black" Font-Underline="false" CommandName="SmallUp" CommandArgument='<%#Eval("qxid") %>'>上移</asp:LinkButton>--%>
                                                    </td>
                                                   
                                                </tr>
                                            </table>
                                        </td>
                                      </tr>
                                      <tr>
                                        <td colspan="2">
                                            <asp:DataList ID="DataList3" runat="server" Width="100%">
                                                <ItemTemplate>
                                                    <table width="100%" cellpadding="0" cellspacing="0" style="border-top-style: solid; border-top-width: 1px; border-top-color: #808080">
                                                        <tr οnmοuseοver="this.style.backgroundColor='#9abbee'"   οnmοuseοut="this.style.backgroundColor='' ">
                                                            <td style="padding-left:100px;width:50%; border-right-style: solid; border-right-width: 1px; border-right-color: #808080;">
                                                                <table width="100%" cellpadding="0" cellspacing="0">
                                                                    <tr>
                                                                        <td width="5%"><img id="img3" runat="server" alt=""  src="../Back/Images/-.gif"/></td>
                                                                        <td width="95%" style="padding-top:3px; "><%#DataBinder.Eval(Container.DataItem,"qxmc") %>
                                                                            <asp:HiddenField ID="HiddenField3" runat="server" Value='<%#DataBinder.Eval(Container.DataItem,"qxid") %>' />
                                                                        </td>
                                                                    </tr>
                                                                </table>
                                                            </td>
                                                            <td style="width:50%">
                                                                <table width="100%" cellpadding="0" cellspacing="0">
                                                                    <tr>
                                                                        <td style="width:20%" align="center"></td>
                                                                        <td style="width:20%" align="center">
                                                                        </td>
                                                                        <td style="width:20%" align="center">
                                                                            <asp:LinkButton ID="LinkButton6" runat="server" PostBackUrl='<%#"../back/changekind.aspx?csid="+Eval("qxid").ToString()+""%>' CommandName="update3" ForeColor="Black" Font-Underline="false">修改</asp:LinkButton>
                                                                        </td>
                                                                        <td style="width:20%" align="center">
                                                                            <asp:LinkButton ID="LinkButton7" runat="server" CommandName="delete3" ForeColor="Black" Font-Underline="false" OnClientClick="infor()">删除</asp:LinkButton>
                                                                        </td>
                                                                       <td style="width:20%" align="center">
                                                                            <%--<img src="Images/013.gif" /><asp:LinkButton ID="LinkButton5" runat="server" ForeColor="Black" Font-Underline="false" CommandName="SmallUp" CommandArgument='<%#Eval("qxid") %>'>上移</asp:LinkButton>--%>
                                                                        </td>
                                                                       
                                                                    </tr>
                                                                </table>
                                                            </td>
                                                        </tr>
                                                    </table>
                                                </ItemTemplate>
                                            </asp:DataList>
                                        </td>
                                      </tr>
                                    </table>
                                </ItemTemplate>
                                <EditItemTemplate>
                                    <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
                                    <br />
                                    <asp:Button ID="Button3" runat="server" Text="确定" CommandName="editor2" />
                                    <asp:Button ID="Button4" runat="server" Text="取消" CommandName="cancel" />
                                </EditItemTemplate>
                            </asp:DataList>
                        </td>
                    </tr>
                </table>
            </ItemTemplate>
            <EditItemTemplate>
                <asp:TextBox ID="TextBox1" runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"qxmc") %>'></asp:TextBox>
                <br />
                <asp:Button ID="Button1" runat="server" Text="确定" CommandName="editor1" />
                <asp:Button ID="Button2" runat="server" Text="取消"  CommandName="cancel"/>
            </EditItemTemplate>
        </asp:DataList>
    </div>
    </div>
    </ContentTemplate>
    </asp:UpdatePanel>
    </form>
</body>
</html>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值