Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. pass values to 2010 control

pass values to 2010 control

Scheduled Pinned Locked Moved ASP.NET
csharpasp-netquestion
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    dcof
    wrote on last edited by
    #1

    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")); } }[^]

    I 1 Reply Last reply
    0
    • D dcof

      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")); } }[^]

      I Offline
      I Offline
      Ibrahim Hebish
      wrote on last edited by
      #2

      You can try to make this select statement in a string variable so you can concatinate your string variable in the where clause Like that

      string query="select p.Hnumber from dbo.Org o inner join Pl p on
      o.OrganizationID =p.OrganizationID where
      OrganizationName='"+AnyStringVariable+"'";

      so that you can add any value in the where clause. Try This , if it is not working , try to contact me . Good Luck :)

      Sincerely, Ibrahim Hebeish | SoftwareDeveloper | Portal Services | EgyptNetwork(Com) M: +201281744594 Email: i.hebeish@egyptnetwork.com

      U 1 Reply Last reply
      0
      • I Ibrahim Hebish

        You can try to make this select statement in a string variable so you can concatinate your string variable in the where clause Like that

        string query="select p.Hnumber from dbo.Org o inner join Pl p on
        o.OrganizationID =p.OrganizationID where
        OrganizationName='"+AnyStringVariable+"'";

        so that you can add any value in the where clause. Try This , if it is not working , try to contact me . Good Luck :)

        Sincerely, Ibrahim Hebeish | SoftwareDeveloper | Portal Services | EgyptNetwork(Com) M: +201281744594 Email: i.hebeish@egyptnetwork.com

        U Offline
        U Offline
        umeshdwivedi kanpur
        wrote on last edited by
        #3

        how can

        I 1 Reply Last reply
        0
        • U umeshdwivedi kanpur

          how can

          I Offline
          I Offline
          Ibrahim Hebish
          wrote on last edited by
          #4

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

          you can make it like that :

          // You Can take a value from any control
          // (textbox, dropDownList,.... , etc.)

          string organizationName=_organizationNameTextBox.Text;

          string query="select p.Hnumber from dbo.Org o inner join Pl p on
          o.OrganizationID =p.OrganizationID where
          OrganizationName='"+organizationName+"'";

          DBConnection.ExecuteQuery(query)

          so you can pass any value to the "Where" Clause (it is simple way). or you can make a Stored-Procedure that makes the same Query & takes a parameter for the Where clause and this is the (recommended solution).

          Sincerely, Ibrahim Hebeish | SoftwareDeveloper | Portal Services | EgyptNetwork(Com) M: +201281744594 Email: i.hebeish@egyptnetwork.com

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups