Skip to main content

How to create Nested Data list, data grid or data repeater simple

Dear All,
The simplest way of create nested datalist with parent child table relation is given below:

 protected void loadData()
           //Note: For Define your connection string i am not writing it because it is in my web.config and i load it through my internal class

             DataSet ds = new DataSet();
          // my private class that contains sql execute funtions, I pass the SQL parameters and Values through array
            UDF myudf = new UDF();
            string spName = "bvs_payInvoice";
            string[] field = new string[5];
            string[] fieldValue = new string[field.Length];

            field[0] = "@startDate";
            field[1] = "@endDate";
            field[2] = "@searchType";
            field[3] = "@keyWord";
            field[4] = "@status";
            fieldValue[0] = startDate;
            fieldValue[1] = endDate;
            fieldValue[2] = searchType;
            fieldValue[3] = keyword;
            fieldValue[4] = status;
            // this is my own function that execute the data set through passing array parameters
            ds = myudf.loadDataSet(spName, field, fieldValue);
           // this is an actual trick
           // Load two table in one ds (see my next post)

           // define Parent column in which you need to create the relation
            DataColumn parentColumn1 = ds.Tables[0].Columns[1];

           // Define Child column in which you need to create the relation 
            DataColumn childColumn1 = ds.Tables[1].Columns[1];

           // Define relation, the "detailDataset" is the name of your virtual table that you can use in your front end code.. or aspx page
            DataRelation dr = new DataRelation("detailDataset", parentColumn1, childColumn1, false);

           // Add relation with your ds  
           // Assigning Data source and binding.
             DataList1.DataSource = ds;

Front End

                         // Call your main parent dataset fields
       <asp:DataList ID="DataList1"  >
<ItemTemplate><%# DataBinder.Eval(Container.DataItem, "Your column Name")%>

                        // Create nested datalist 
     <asp:DataList ID="DataList2" runat="server"  datasource='<%# DataBinder.Eval(Container, "DataItem.detailDataset") %>'>
                 // Call your main Child dataset fields 
                   <ItemTemplate>   <%# DataBinder.Eval(Container.DataItem, "Your column Name")%></ItemTemplate>



How you access the nested DataList items

first you need to initialize the controller
 DropDownList ddlhrs= default (DropDownList);
HiddenField parentRefId = default (HiddenField);
same like above you need to initialize your all controllers

//PreviewForm is your datalist name
  for (int i = 0; i <= previewForm.Items.Count - 1; i++)
   ddlhrs = (DropDownList)previewForm.Items[i].FindControl("DropDownList1");

   // access your control

   //assigned  nested datalist to control
    dl1 = (DataList)previewForm.Items[i].FindControl("DataList2");
    for (int j = 0; j <= dl1.Items.Count - 1; j++)
                   //Assign the Refrence in child datalist controller
                    parentRefId = (HiddenField)dl1.Items[j].FindControl("parentRefId");


You can use the same technique with Data table, data list, and repeater or data table + repeater or data table + data list or data list + data table in short you create any sort of combination

I hope this post helps you allot

Rashid Imran Bilgrami
Best visualization 


Popular posts from this blog

How to convert and crack windows server 2012 from Evaluation to Full

Dear All

This is a way how you Convert Evalution to Full


Open CMD and run following command
DISM /online /Get-CurrentEdition

<edition ID> is like ServerStandard with out Eval

Step 2:
DISM /online /Set-Edition:<edition ID> /ProductKey:XXXXX-XXXXX-XXXXX-XXXXX-XXXXX /AcceptEula

Serial Key

Windows Server 2012
DataCenter: 48HP8-DN98B-MYWDG-T2DCC-8W83P
Datacenter: Y4TGP-NPTV9-HTC2H-7MGQ3-DV4TW

Standard: XC9B7-NBPP2-83J2H-RHMBY-92BT4

Server Essentials:K2XGM-NMBT3-2R6Q8-WF2FK-P36R2

For Standard R2 here is a command
For R2 its like that
DISM /online /Set-Edition:ServerStandard /ProductKey:DBGBW-NPF86-BJVTX-K3WKJ-MTB6V /AcceptEula


Calling LoadLibraryEx on ISAPI filter “C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_filter.dll” failed

Dear Readers
if you get the error

Calling LoadLibraryEx on ISAPI filter “C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_filter.dll” failed

Here is the solution 
Get a command prompt in administrator mode and go to C:\Windows\Microsoft .NET\FrameWork64\
and run aspnet_regiis -r. This will re-register the right libraries. It has happened twice already to me.
For other frameworks (32 bit or other versions of .net make sure you go to the correct folder (i.e. Framework/, etc.)

xxxx is the the number which is present with the folder name so i suggest you guys to check the folder name in your directory

If "run aspnet_regiis -r" is not working and if you get the error run is not recognized command then just type " aspnet_regiis -r" it will run fine

Reason of problem
Your frame work has been change may be you have install the lower version on the higher version or may be because of any reason you have register another version in your IIS, in my cas…

RegisterStartupScript updated way to right Java script JS (Javascript) in code behind also work with update panel

Dear All
RegisterStartupScript is obsolete now the new way that works with update panel  is given below its is code behind file code also

VB Code Dim csname1 As String = "PopupScript"
Dim cstype As Type = Me.GetType()
Dim cs As ClientScriptManager = Page.ClientScript
Dim cstext1 As String = "alert('Your message');"
cs.RegisterStartupScript(cstype, csname1, cstext1, True)

C# Code
String csname1 = "PopupScript";
Type cstype = this.GetType();
ClientScriptManager cs = Page.ClientScript;
String cstext1 = "alert('Hello World');"; cs.RegisterStartupScript(cstype, csname1, cstext1, true);
I hope it will help you also 
Regards  Rashid Imran Bilgrami