Click here to Skip to main content
12,954,464 members (51,203 online)
Rate this:
 
Please Sign up or sign in to vote.
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 6-Feb-13 6:24am
lalitkr1.8K
Updated 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 :) i saw that solution given below and applied according to ur requirement.
  Permalink  
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 Moideen 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 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
Top Experts
Last 24hrsThis month
OriginalGriff 6,539
CHill60 3,490
Maciej Los 3,143
ppolymorphe 2,030
Jochen Arndt 1,975


Advertise | Privacy | Mobile
Web02 | 2.8.170525.1 | Last Updated 7 Feb 2013
Copyright © CodeProject, 1999-2017
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