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

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

SugarCRM Footer Logo Remove & SugerCRM violation Message Remove

Hi Reader, Let us discuss about how to remove the SugarCRM Footer logo.. You all are aware of the power of the SugarCRM Tool and also must be very eager to remove the footer in order to make it look more professional. So below mentioned are some tricks for removing the footer from SugarCRM Community edition. 1)  O pen-modules/Administration/ updater_utils.php Add-exit() ; in between   function check_now()   and   return . any where By doing this u can remove 'powered by sugar crm' footer logo. 2) Go to  modules/Trackers/Tracker.php, line 128, in the 'logPage' function. Drop the 'echo' statement. 3) Now to root(Sugarfolder)\include\mvc\view\sugarview.php and modify the line array(show header => true, show subpanel => true...........and so on) and make the changes to showfooter=>true to  showfooter=>false Now how you remove the violation  Go to include /utils/ mvc_utils.php and remove the line or code b...

DNN 7 Won't go into edit mode or not working with control bar

Dear All, Today when i install the DNN 7 then i found and issue in edit mode after installation. The problem is when i go to edit mode the page refresh with out enabling the edit mode, after a short research on Google i found the solution. I hppe it save your time 1. backup your web.config 2. Open your web.config in a text editor 3. within the web.config file, find the <system.webserver><modules> section. 4.  If the <modules> section says <modules runAllManagedModulesForAllRequests="false"> change it to <modules runAllManagedModulesForAllRequests="true"> OR  if it just says <modules>, change it to <modules runAllManagedModulesForAllRequests="true"> 5. Save the config file. 6. Retry by refreshing the page and trying again.  You can also test this out by trying to a do a journal post (which also uses the services framework in an authenticated way. If some how its will not work then, you must chang...