c# - Searching data from database using checkbox list for a ecommerce website -


hello sir wanna search data using checkbox aur checkboxlist if select 2 checkbox wanna data of both checkbox id's code giving me 1 data @ time. please give me demo code type of query.

private void checkboxlistbind() {

    sqlconnection con = new sqlconnection("data source=.\\sqlexpress;attachdbfilename=c:\\users\\flagbits\\documents\\visual studio 2010\\websites\\checkboxlist\\app_data\\database.mdf;integrated security=true;user instance=true");     con.open();     string query = "select * student id='" + checkbox1.text + "'";     sqlcommand cmd = new sqlcommand(query, con);     sqldatareader dr;     dr = cmd.executereader();     gridview1.datasource = dr;     gridview1.databind();    } private void checkboxlistbind2() {      sqlconnection con = new sqlconnection("data source=.\\sqlexpress;attachdbfilename=c:\\users\\flagbits\\documents\\visual studio 2010\\websites\\checkboxlist\\app_data\\database.mdf;integrated security=true;user instance=true");     con.open();     string query = "select * student id='" + checkbox2.text + "'";     sqlcommand cmd = new sqlcommand(query, con);     sqldatareader dr;     dr = cmd.executereader();     gridview1.datasource = dr;     gridview1.databind();  }   protected void checkbox1_checkedchanged(object sender, eventargs e) {        if (checkbox1.checked == true)     {         checkboxlistbind();     }  } protected void checkbox2_checkedchanged(object sender, eventargs e) {     if (checkbox2.checked == true)     {         checkboxlistbind();         checkboxlistbind2();     } 

you need iterate through checkboxlist , test selected value each item , build string containing each of options.

    string queryparam = '';       (int i=0; i<checkboxlist1.items.count; i++) {          if (checkboxlist1.items[i].selected)             {  queryparam  += (queryparam.length = 0) ? "id = " + checkboxlist1.items[i].text : " or id = "  checkboxlist1.items[i].text }       } 

this should give idea start with.


Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -