Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have a query on data binding in checkboxlist

for example i have saved the data in the database in the following manner as below

ExmpName Country

ravi india , US, UK , China
manan india , germany , japan

the above mentioned data exist in my table now how can i show the same data for empname in the textbox and country in the checkbox list in the asp.net page using C# , pls guide me in this regard
Posted
Updated 6-Feb-13 6:34am
v2

C#
SqlConnection sqlconn = new SqlConnection("server=.\\sqlexpress;database=forum;integrated security=true");
       SqlCommand sqlcomm = new SqlCommand("select country from countryname ", sqlconn);
       sqlconn.Open();
       SqlDataReader dr = sqlcomm.ExecuteReader();
       if (dr.Read())
       {
           string Country = dr["Country"].ToString();
           var toArray = Country.Split(',');
           foreach (var s in toArray)
           {
               CheckBoxList1.Items.Add(s);
           }



           dr.Close();
           sqlconn.Close();


       }

I have Updated My Answer this is working i have Checked :) i saw that solution given below and applied according to ur requirement.
 
Share this answer
 
v2
Comments
lalitkr 7-Feb-13 5:53am    
Hi,

Thanks , But here the country like india , china , japan lie in the one cell and seprated by comma so how will i read the values one by one
Jameel VM 7-Feb-13 9:13am    
can you eloborate the question?
Try this
C#
//for example this is your countries column from the table
           string country = "UK,London,America";
           var toArray = country.Split(',');
           foreach (var s in toArray)
           {
               CheckBoxList1.Items.Add(s);
           }


Hope this helps
 
Share this answer
 
v2
Comments
Surendra0x2 7-Feb-13 8:30am    
+5 Dude :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900