注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

回忆之旅

我很向往山村的农庄生活,他们的热情,让我无法抗拒! 51EOO.COM

 
 
 

日志

 
 

动态创建DataList绑定数据  

2010-01-03 09:27:32|  分类: 技术分享 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

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

public partial class AdminManager_ProductClass_Manager : System.Web.UI.Page
{
    TZDM.BLL.ProductClass bll = new TZDM.BLL.ProductClass();
    protected void Page_Load(object sender, EventArgs e)
    {
        CreateDataList("Big", BigClass());
    }


    public void CreateDataList(string id, DataTable table)
    {
        DataList dlInfo = new DataList();
        dlInfo.ID = id;
        dlInfo.DataKeyField = "PC_ID";
        dlInfo.RepeatColumns = 1;
        dlInfo.RepeatDirection = RepeatDirection.Vertical;
        dlInfo.ItemDataBound += new DataListItemEventHandler(dlInfo_ItemDataBound); //添加数据绑定事件
        dlInfo.ItemCommand+=new DataListCommandEventHandler(dlInfo_ItemCommand);
        dlInfo.ItemTemplate = new CMyTemplate("lItem");
        dlInfo.DataSource = table;
        dlInfo.DataBind();       
        form1.Controls.Add(dlInfo);
    }

    //大类
    protected DataTable BigClass()
    {
        return bll.SelectBigClass();
    }

    //小类
    protected DataTable SmallClass(int PC_ID)
    {
        return bll.SelectSmallClass(PC_ID);
    }


      public string GetStringByControl(System.Web.UI.Control theControl)
    {
        System.Text.StringBuilder sb = new System.Text.StringBuilder();
        System.IO.StringWriter writer = new System.IO.StringWriter(sb);
        System.Web.UI.HtmlTextWriter htw = new System.Web.UI.HtmlTextWriter(writer);
        theControl.RenderControl(htw);

        return sb.ToString();
    }


    private void dlInfo_ItemDataBound(object sender, System.Web.UI.WebControls.DataListItemEventArgs e)
    {
        LinkButton lItem;
        int ID = 0;
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            lItem = (LinkButton)e.Item.FindControl("lItem");
            if (lItem != null)
            {               
                DataRowView view = ((DataRowView)e.Item.DataItem);
                lItem.Text = "<div onmousemove=this.className='DL_ColumnMouse' onmouseout=this.className='DL_Column' class='DL_Column'>" + view.Row["PC_Name"].ToString() + "," + view.Row["NextNumber"].ToString() + "</div>";
                if (view.Row["NextNumber"].ToString() == "0")
                {

                }
                else
                {
                    lItem.CommandName = "lItem";
                    lItem.CommandArgument = view.Row["PC_ID"].ToString();
                }
            }
        }

    }


    protected void dlInfo_ItemCommand(object source, DataListCommandEventArgs e)
    {
        if (e.CommandName.ToString() == "lItem")
        {
            CreateDataList(e.CommandArgument.ToString(), SmallClass(int.Parse(e.CommandArgument.ToString())));
        }
    }

}

public class CMyTemplate : ITemplate
{
    private string pControlName; //控件名称  

    public CMyTemplate(string ControlName)
    {
        pControlName = ControlName;
    }

    public void InstantiateIn(Control container)
    {
        LinkButton lItem = new LinkButton();
        lItem.ID = pControlName;
        container.Controls.Add(lItem);
    }
}



动态创建DataList绑定数据 - Tony - 回忆之旅
  评论这张
 
阅读(355)| 评论(0)
推荐 转载

历史上的今天

在LOFTER的更多文章

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017