Another nesting of DataGrid and DataList--a better way

Source: Internet
Author: User
Tags eval implement
Datagrid
Disadvantages relative to the previous use of relation:
1. Cannot limit the number of records returned; 2. State time inconvenient, not even the state set; 3. The procedure is simple, but not easy to understand. 4. Possible nesting of more than three layers is not easy to implement.
The nesting scheme given this time, the use of the ItemDataBound event nesting, easy to implement, it is easier to understand. and solved the above four problems.
Here's the main code:
<asp:datalist id= "Dlist_class" datakeyfield= "NavigatorId"
Backcolor= "#ffffff" borderwidth= "0px" cellpadding= "1"
Showfooter= "false" Showheader= "false" runat= "Server"
cellspacing= "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>
<asp:datagrid Id=dg_subclass width=315px Runat=server
Autogeneratecolumns= "false"
Showheader= "false" Showfooter= "false" pagesize= "ten" 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 Iorder, ilevel, Iparentid, NavigatorId, Nodecaption,moduleid, ModuleTy PE 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 ();
}
}
====================
More content, welcome to visit Ms.mblogger.cn/nono


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.