Mohamad Simo

Mohamad Simo

  • NA
  • 14
  • 8.9k

Use class or one method to bind three cascading DDL

May 9 2016 3:58 AM

Hi

I trying my best to make my web application faster as much as i can, so one of what i am looking is reducing the codes into each page. So i have three DDL as mention below they do the same job to bind the DDL's depending on cookie value. So how i can create a class and use it for to bind all DDL's or i dont know if it possible to bind three of those DDLs into one method as below method as they are doing the same job?

-StateHPDDL

-BizstateHPFilterDDL

-filterstathpjob

the code used for each DDL in page_load is as below

  1. if (!IsPostBack)  
  2.             {  
  3.                 if (cookie["Location"] == null)  
  4.                 {  
  5.   
  6.                     DataTable filterstathpAdsDT = new DataTable();  
  7.   
  8.                     using (SqlConnection filterstathpAdsCon = new SqlConnection(cs))  
  9.                     {  
  10.   
  11.                         SqlCommand filterstathpAdsCMD = new SqlCommand("SELECT State FROM State WHERE Country = @Location", filterstathpAdsCon);  
  12.   
  13.                         var Location = cookie.Value;  
  14.   
  15.                         filterstathpAdsCMD.Parameters.AddWithValue("@Location", Location);  
  16.   
  17.   
  18.                         SqlDataAdapter filterstathpAdsAP = new SqlDataAdapter();  
  19.                         filterstathpAdsAP.SelectCommand = filterstathpAdsCMD;  
  20.                         filterstathpAdsAP.Fill(filterstathpAdsDT);  
  21.   
  22.                         StateHPDDL.DataSource = filterstathpAdsDT;  
  23.                         StateHPDDL.DataTextField = "State";  
  24.   
  25.                         StateHPDDL.DataBind();  
  26.                     }  
  27.   
  28.                     StateHPDDL.Items.Insert(0, new ListItem("Select Province"""));  
  29.                 }  
  30.   
  31.   
  32.             }  

Answers (2)