?
Solved

CheckBoxList setting value

Posted on 2011-03-09
2
Medium Priority
?
595 Views
Last Modified: 2012-05-11
Hi EE,
I have CheckBoxList on aspx page and adding items from code behind page.
in the following code, how can I set "ID" for value and "Text" for item text to display.

[.aspx]
 <asp:CheckBoxList ID="SectorList" runat="server">
 </asp:CheckBoxList>

[.cs]
while (reader.Read())
 {
string ID = reader["ID"].ToString();
string Text = reader["Text"].ToString();
SectorList.Items.Add(Text);
}


eg.
   <asp:CheckBoxList ID="SectorList" runat="server">
                    <asp:ListItem Value="1">apple</asp:ListItem>
                    <asp:ListItem Value="2">orange</asp:ListItem>
   </asp:CheckBoxList>
0
Comment
Question by:saloj
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 29

Accepted Solution

by:
Paul Jackson earned 1600 total points
ID: 35089639
SectorList.Items.Add(new ListItem(Text, ID));
0
 
LVL 10

Assisted Solution

by:hosneylk
hosneylk earned 400 total points
ID: 35089902
you can also do it this way instead of looping.
SectorList.DataValueField = "ID";
SectorList.DataTextField = "Text";
SectorList.DataSource = reader;
SectorList.DataBind();

Open in new window

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question