using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Data.SqlClient; /// /// Summary description for FillDD /// public class FillDD { //SqlConnection con = new SqlConnection(ConfigurationSettings.AppSettings["con"]); SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["connectionstring"].ConnectionString); public FillDD() { // TODO: Add constructor logic here } public void Get_DDList(ref DropDownList Drd, String idF, String txtF, String tbl, ref Label err) { try { Drd.Items.Clear(); SqlCommand Cmd = new SqlCommand("SELECT " + idF + ", " + txtF + " FROM " + tbl + " order by " + txtF + " asc", con); con.Open(); Drd.DataSource = Cmd.ExecuteReader(); Drd.DataTextField = txtF; Drd.DataValueField = idF; Drd.DataBind(); } catch (Exception exp) { err.Text = ("DropDownList Alert! : " + exp.Message); } finally { con.Close(); } } public void Get_DDListWhr(ref DropDownList Drd, String idF, String txtF, String tbl, String Whr, ref Label err) { try { Drd.Items.Clear(); SqlCommand Cmd = new SqlCommand("SELECT " + idF + ", " + txtF + " FROM " + tbl + " " + Whr + " order by " + txtF + " asc", con); con.Open(); Drd.DataSource = Cmd.ExecuteReader(); Drd.DataTextField = txtF; Drd.DataValueField = idF; Drd.DataBind(); } catch (Exception exp) { err.Text = ("DropDownList Alert! : " + exp.Message); } finally { con.Close(); } } public void Get_DDListDist(ref DropDownList Drd, String txtF, String tbl, String Whr, ref Label err) { try { Drd.Items.Clear(); SqlCommand Cmd = new SqlCommand("SELECT Distinct(" + txtF + ") FROM " + tbl + " " + Whr + " order by " + txtF + " asc", con); con.Open(); Drd.DataSource = Cmd.ExecuteReader(); Drd.DataTextField = txtF; Drd.DataValueField = txtF; Drd.DataBind(); } catch (Exception exp) { err.Text = ("DropDownList Alert! : " + exp.Message); } finally { con.Close(); } } public void Get_DDList2(ref DropDownList Drd, String idF, String txtF, String tbl, String condition, ref Label err) { try { Drd.Items.Clear(); SqlCommand Cmd = new SqlCommand("SELECT " + idF + ", " + txtF + " FROM " + tbl + " where ClientName = '" + condition + "' ", con); con.Open(); Drd.DataSource = Cmd.ExecuteReader(); Drd.DataTextField = txtF; Drd.DataValueField = idF; Drd.DataBind(); } catch (Exception exp) { err.Text = ("DropDownList Alert! : " + exp.Message); } finally { con.Close(); } } public void Get_RecordsSelected(ref DropDownList drd, string cursel, ref Label err) { try { drd.ClearSelection(); ListItem item; item = drd.Items.FindByValue(cursel); if (!(item == null)) { item.Selected = true; } } catch (Exception ex) { err.Text = "DD Error :" + ex.Message; } } public void Get_DDSelectByText(ref DropDownList ddl, string val) { ListItem li = default(ListItem); li = ddl.Items.FindByText(val); if ((li != null)) li.Selected = true; } public void Get_DDSelectByValue(ref DropDownList ddl, string val) { ListItem li = default(ListItem); li = ddl.Items.FindByValue(val); if ((li != null)) li.Selected = true; } }