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  
            ds.Relations.Add(dr);
         
           // Assigning Data source and binding.
             DataList1.DataSource = ds;
            DataList1.DataBind();


******************
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>
   

</asp:DataList>
               
</ItemTemplate>                        
                   

</asp:DataList>



******************
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
  ddlhrs.SelectedValue.ToString();

   //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");
                    parentRefId.Value.ToString();
                }

}








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

Regards
Rashid Imran Bilgrami
CEO
Best visualization
http://www.bestvisualization.com 

Comments

Popular posts from this blog

OLEDB jet 4.0 driver In Vista 64bit / he 'Microsoft.Jet.OLEDB.4.0' provider is not registered on the local machine

Well i think you must be thankful for me specailly for this research i am really getting the solution after 6 month research that is how to enable the oledb jet 4.0 driver in vista, i read arround 100s of articles and maximum said that is not possible to enable it and ala bla well at the end i got the answer that is so easy Acctually that is correct that oledb jet 4.0 driver is not avaialble for 64 bit but if you run your IIS on 32 bit instead of 64 then Oledb jet will working fine Here are the steps Click on the Start > Program > Administrative Tool > IIS Management panel Select the Computer name Right click on the application pool and select properties Select "TRUE" in Enable 32 Bit Application by default it is false Then this problem will resolve if you need any assitance then feel free to email me rashidbilgrami@hotmail.com Regards Rashid Imran Bilgrami CEO Best visualization www.bestvisualization.com

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

Dear All This is a way how you Convert Evalution to Full Step1: 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 WINDOWS SERVER 2012 Serial Key Windows Server 2012 DataCenter: 48HP8-DN98B-MYWDG-T2DCC-8W83P Datacenter: Y4TGP-NPTV9-HTC2H-7MGQ3-DV4TW Standard: XC9B7-NBPP2-83J2H-RHMBY-92BT4 Standard R2: DBGBW-NPF86-BJVTX-K3WKJ-MTB6V 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 Regards

SQL Agent disabled / how to enable SQL agent

Dear Readers, Today i found that SQL agent is disabled and i can active through the below process First you can check first these points Go to run type services.msc Right click on the SQL Server Agent (MSSQLSERVER) Then check in the properties your startup type might be disabled change it to automatic or manual and try again it will enable the start option If the above process not workable then check this one SQL Server blocked access to procedure 'dbo.sp_get_sqlagent_properties' of component 'Agent XPs' because this component is turned off as part of the security configuration for this server. A system administrator can enable the use of 'Agent XPs' by using sp_configure. For more information about enabling 'Agent XPs', see "Surface Area Configuration" in SQL Server Books Online. You need to run the following script under you SQL management Studio 1) Open the new query 2) Past the code sp_configure 'show