Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET
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 6-Feb-13 6:24am
lalitkr1.5K
Edited 6-Feb-13 6:34am
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

 
 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 Smile | :) i saw that solution given below and applied according to ur requirement.
  Permalink  
v2
Comments
lalitkr at 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 Moideen at 7-Feb-13 9:13am
   
can you eloborate the question?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Try this
//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
  Permalink  
v2
Comments
Surendra0x2 at 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)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 385
1 George Jonsson 339
2 CPallini 335
3 BillWoodruff 314
4 OriginalGriff 227
0 OriginalGriff 5,030
1 CPallini 4,225
2 Sergey Alexandrovich Kryukov 3,604
3 George Jonsson 2,831
4 Gihan Liyanage 2,386


Advertise | Privacy | Mobile
Web04 | 2.8.140916.1 | Last Updated 7 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100