dc

dc

  • NA
  • 663
  • 0

asp.net 2010 pass value to control

Oct 20 2011 6:17 PM

I am adding a checkboxlist control to a C# asp.net 2010 since I am new to working with web pages. The following code works if I hardcode the value in the where clause. However, I want to pass the value in the where clause as a paramter. Thus can you tell me what I could change in the code below to pass the value to the where statement not as a hardcoded value?

DBConnection.FillAttChkListBox(ChkBoxLstPlan, "Hnumber", "Hnumber",
            DBConnection.ExecuteQuery("select p.Hnumber from dbo.Org o inner join Pl p on o.OrganizationID =p.OrganizationID where OrganizationName='orgname1'"), false);


  public static DataTable ExecuteQuery(string SQLstring)
        {
            string constr = ConfigurationManager.ConnectionStrings["DBConnectionString"].ConnectionString;
            //string constr = ConfigurationManager.ConnectionStrings["Client_ServiceConnectionString"].ConnectionString;
            SqlConnection conn = new SqlConnection(constr);
            DataTable dt = new DataTable("tbl");

            using (conn)
            {
                conn.Open();
                SqlCommand comm = new SqlCommand(SQLstring, conn);
                comm.CommandTimeout = 0;
                SqlDataAdapter da = new SqlDataAdapter(comm);
                da.Fill(dt);
            }

            return dt;
        }


 public static void FillAttChkListBox(CheckBoxList chklistBox, String dataValueField, string dataTextField, DataTable dataTbl, bool bHasBlank)
         {
            chklistBox.DataTextField = dataTextField;
            chklistBox.DataValueField = dataValueField;
            chklistBox.DataSource = dataTbl;
            chklistBox.DataBind();

            if (bHasBlank)
            {
            chklistBox.Items.Insert(0, new ListItem());
               // chklistBox.Items.Insert(1, new ListItem("All"));
            }
        }


Answers (1)