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

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

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…

Multi Language Website In DNN Or Content Localization in DNN

Dear Readers
Before that when we create the Multi Language website in dnn we always create two portal but with DNN 5.x version you will use the language resource for creating multi language website website

You are facing two major challenges to create Multi language website
1) Translation of the DNN controls in to local language
2) Translate your own pages navigation or menu in to multi languages
3) Translate your own custom content in to local language
4) Translate your custom modules in to the local languages

Lets start with the first challange

Challenge 1: Translation of the DNN controls in to local language 
This is an easiest part, you can follow the steps achieve this challenge

1) Login with your host/Admin  account
2) Go to the Admin / Languages
3) Click on ADD Languages
4) Select the language that you need and Add it
5) You will see now two languages in your language section
6) With the list you will see the three option

Static Resources
System | Host |Site

7) you can click on t…