制作Infragistics.WebUI.UltraWebGrid树型

制作Infragistics.WebUI.UltraWebGrid树型
2008年03月14日 星期五 上午 11:29

1.得到数据集

public DataSet GetAllLvlMenu()
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append(" declare @lvl int ");
            strSql.Append(" declare @i int ");
            // strSql.Append(" select @lvl=max(lvl)+5 from Member_menu ");
            strSql.Append(" set @lvl=19 ");
            strSql.Append(" set @i=0 ");
            strSql.Append(" while @i<=@lvl ");
            strSql.Append(" begin ");
            strSql.Append(" select *,SUBSTRING(Code,1,len(Code)-3) as PCode from Member_Menu where lvl=@i order by ShowOrder ");
            strSql.Append(" set @i=@i+1 ");
            strSql.Append(" end ");
            return DbHelperSQL.Query(strSql.ToString());
        }

2. 得到集合并建立主子表关系

DataSet ds = Member.GetAllLvlMenu();
        //表之间建立主子表关系
        for (int i = 0; i <ds.Tables.Count-1; i++)
        {
            ds.Relations.Add(ds.Tables[i].Columns["Code"], ds.Tables[i + 1].Columns["PCode"]);
        }

3.绑定

UltraWebGrid1.DataSource = ds;
        UltraWebGrid1.DataBind();

4.前台添加功能

   function UltraWebGrid_Add(objID)
    {
       var grid=igtbl_getGridById(objID);
       var row=grid.getActiveRow();
       if(row!=null)
       {         
         if(row.Rows!=null) row.Rows.addNew();
         else
         {       

             //由于我数据库设计code的长度是60,每层是3位,所以这里只能到20层
             if(row.Band.Index<19) igtbl_addNew(objID,row.Band.Index+1);
             else igtbl_addNew(objID,row.Band.Index);
         }
       }
       else igtbl_addNew(objID,0);
       return false;     
    }

5.后台保存

protected void SaveButton_Click(object sender, EventArgs e)
    {
        try
        {
            SaveMenu(this.UltraWebGrid1.Rows);          
            MessageBox.Show(this, "sucess!");
        }
        catch(Exception ex)
        {
            MessageBox.Show(this, "fail!");
        }      
    }
    private void SaveMenu(RowsCollection Rows)
    {        
            for (int i = 0; i < Rows.Count; i++)
            {
                if (Rows[i].DataChanged == DataChanged.Modified || Rows[i].DataChanged == DataChanged.Added)
                {
                    Member_MenuInfo menu = new Member_MenuInfo();
                    string ParentCode = "";                  
                    menu.Lvl = Rows.Band.Index;
                    if (Rows[i].Cells.FromKey("Chinese").Value != null)
                        menu.Chinese = Rows[i].Cells.FromKey("Chinese").Value.ToString();
                    if (Rows[i].Cells.FromKey("Russian").Value != null)
                        menu.Russian = Rows[i].Cells.FromKey("Russian").Value.ToString();
                    if (Rows[i].Cells.FromKey("English").Value != null)
                        menu.English = Rows[i].Cells.FromKey("English").Value.ToString();
                    if (Rows[i].Cells.FromKey("URL").Value != null)
                        menu.URL = Rows[i].Cells.FromKey("URL").Value.ToString();
                    if (Rows[i].Cells.FromKey("ImagePath").Value != null)
                        menu.ImagePath = Rows[i].Cells.FromKey("ImagePath").Value.ToString();
                 
                    menu.IsShow = (bool)Rows[i].Cells.FromKey("IsShow").Value;                 
                    if (Rows[i].Cells.FromKey("ShowOrder").Value != null)
                        menu.ShowOrder = (int)Rows[i].Cells.FromKey("ShowOrder").Value;

                    if (Rows[i].DataChanged == DataChanged.Added)
                    {
                        menu.MenuId = System.Guid.NewGuid();
                        if (Rows[i].ParentRow != null)
                            ParentCode = Rows[i].ParentRow.Cells.FromKey("Code").Value.ToString();
                        Member.Member_MenuAdd(menu, ParentCode);
                        menu = Member.GetMember_MenuInfo(menu.MenuId);
                        Rows[i].Cells.FromKey("MenuId").Value = menu.MenuId;
                        Rows[i].Cells.FromKey("Code").Value = menu.Code;
                        Rows[i].Cells.FromKey("PCode").Value = ParentCode;
                    }
                    else if (Rows[i].DataChanged == DataChanged.Modified)
                    {
                        menu.MenuId = (Guid)Rows[i].Cells.FromKey("MenuId").Value;
                        menu.Code = Rows[i].Cells.FromKey("Code").Value.ToString();
                        Member.Member_MenuUpdate(menu);
                    }
                }
                if (Rows[i].Rows != null) SaveMenu(Rows[i].Rows);
            }
    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值