0 I assume you are putting checked items inside an array or list. so your code should be like below
string query;
if(checkedcount==1)
{
query="select "+checkedvalue[0]+" from tablename";
}
else
{
StringBuilder columns=new StringBuilder();
for(int i=0;i<checkedValues.Length;i++)
{
if(i<checkedValues.Length-1)
{
columns.Append(checkedValues[i]);
columns.Append(",");
}
else
{
// No more commas needed as this is last column
columns.Append(checkedValue[i]);
}
}
query="select "+columns+" from tablename";
}
execute ur query.
I hope this query helps..This is just a rough code snippet.
Accepted 0 So request you accept all three methods as Answers. This will helpful for others also.
0 Thanks for your valuable suggestions guys....
Problem solved..
Once again thanks
Murali Krishna
0 try...
-- To get all checked items from Checkboxlist using LINQ
using System.Collections.Generic;
using System.Linq;
IEnumerable<string> allCheckedValues = chboxlist.Items
.Cast<ListItem>()
.Where(item => item.Selected)
.Select(item => item.Value);
String ss = "";
foreach (var item in allChecked)
{
ss = (ss == "" ? "[" + item + "]" : ss + ", [" + item + "]");
}
String query1 = String.Format("Select {0} from {1}", ss, "Table1");
If not want to use LINQ, then use for each to loop the checkbox list.
0 private void btn_Click(object sender, EventArgs e)
{
string s = "select ";
for (int i=0;i<checkedListBox1.CheckedItems.Count;i++)
{
if (checkedListBox1.CheckedItems.Count > i)
if (checkedListBox1.CheckedItems.Count-1 == i)
{
s += checkedListBox1.Items[i].ToString() ;
}
else
{
s += checkedListBox1.Items[i].ToString() + " , ";
}
}
label1.Text = s;
}
Try this.