[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

CheckBoxList setting value

Posted on 2011-03-09
2
Medium Priority
?
599 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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

650 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