| 网站首页 | 模板 | 资料 | 源码 | 工具 | 开发 | 设计 | 安全 | 项目 | 网络 | 图片 | 系统 | 数据库 | 博客 | 会员中心 | 小说 | 
MYFTP 精品资料下载
网络学院
学习资料
源码模版
您现在的位置: 精品下载 >> 开发 >> .net >> 文章正文 用户登录 新用户注册
另外一种DataGrid与Datalist的嵌套--更好的方式[原创]            【字体:
另外一种DataGrid与Datalist的嵌套--更好的方式[原创]
作者:佚名    文章来源:不详    点击数:    更新时间:2007-10-7

相对于上一次的使用Relation的缺点:
1. 不能限制返回的纪录数;2. 邦定时不方便,甚至不能邦定上;3. 程序简单,但不容易理解。4. 可能对于三层以上的嵌套不容易实现。
这次给出的嵌套方案,使用的ItemDataBound事件进行嵌套,实现起来很方便,其容易理解。并且解决了以上四个问题。
以下是主要的代码:
<asp:DataList ID="DList_Class" DataKeyField="NavigatorID"
  BackColor="#ffffff"  BorderWidth="0px" CellPadding="1"
  ShowFooter="False" ShowHeader="False"  runat ="server"
  CellSpacing="20" HorizontalAlign="Justify"  RepeatColumns="2"
  RepeatDirection="Horizontal" RepeatLayout="Table" >
    <itemstyle VerticalAlign=Top></itemstyle>
    <itemtemplate>
     <b><%# DataBinder.Eval(Container.DataItem,"NavigatorID") %> @
      <%# DataBinder.Eval(Container.DataItem,"NodeCaption") %></b>
     <hr>
     <asp:DataGrid ID=DG_SubClass Width=315px Runat=server      
     AutoGenerateColumns="false"
     ShowHeader="false" ShowFooter="false" PageSize="10" AllowPaging="true"
     PagerStyle-Visible="false" BorderWidth="1" BackColor="#ffffff" BorderColor="#ffffff"
     CellPadding="0" CellSpacing="0" GridLines=Horizontal
     OnItemDataBound='DG_SubClass_ItemDataBound'>
      <ItemStyle Height="14px" BackColor="#e3f1ff"  CssClass="gridHover"></ItemStyle>
                  
      <Columns>
       <asp:BoundColumn DataField ="ModuleType" ReadOnly=True >
        <ItemStyle Width=25 HorizontalAlign=Center ></ItemStyle>
       </asp:BoundColumn>     
       
       <asp:BoundColumn DataField="NodeCaption" >
        <ItemStyle HorizontalAlign=Left CssClass="nav"></ItemStyle>
       </asp:BoundColumn>
       
       <asp:BoundColumn DataField ="ModuleType" ReadOnly=True>
        <ItemStyle Width=90 HorizontalAlign=Center></ItemStyle>
       </asp:BoundColumn>        
      </Columns>      
     </asp:DataGrid>    
    </itemtemplate>
  </asp:DataList>  

private void DList_Class_ItemDataBound(object sender, System.Web.UI.WebControls.DataListItemEventArgs e)
  {
   if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
   {
    DataGrid dg=(DataGrid)e.Item.FindControl("DG_SubClass");
    string itemIndex =this.DList_Class.DataKeys[e.Item.ItemIndex].ToString();

    string[] strSqlArray =new string[3]{"select Top 10 IOrder, ILevel, IParentID, NavigatorID, NodeCaption,ModuleID, ModuleType from  NavigatorNodes where IParentID in ( ", itemIndex, ");"};
    string strSql=string.Concat(strSqlArray);
    string TableName ="SubClass"+itemIndex;

    this.dbClass.AdapterFill(ds, CommandType.Text, strSql, TableName, new OleDbParameter[0]);

    dg.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler(this.DG_SubClass_ItemDataBound);

    dg.DataSource =ds.Tables[TableName].DefaultView;
    dg.DataBind();
   }
  }
====================
更多内容,欢迎访问ms.mblogger.cn/nono




文章录入:chqnet    责任编辑:chqnet 
  • 上一篇文章:

  • 下一篇文章:
  • 最新热点 最新推荐 相关文章
    一种高效的分页机制,设想阶段
    谢谢,另外一个也搞定,顺便
    一种简单而快速的灰度图处理
    数据库事务处理的另外一种方
    调用另外一个同名的重载函数
    DataGrid 中双向排序的一种办
    [原创]水晶报表数据填充(一
    左侧导航条的一种漂亮移动效
    asp.net里怎么提交数据到另外
    一种简便实效的配置文件读写
      网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)