Solved

Select all items in the listbox in asp.net while loading data...

Posted on 2007-04-09
5
1,247 Views
Last Modified: 2012-05-05
The below code loads the data from the XML to asp.net listbox and assign default selected value to first item.  How could i code so that it will selecte all items  by default?  and also show me how to select the items dynamically based on value from XML (refer below the XML structure)

dsIndexes.ReadXml(filepath);
lstIndexList.DataSource = dsIndexes.Tables[0];
//LBIndexList.DataMember = Indexes;
lstIndexList.DataTextField = dsIndexes.Tables[0].Columns[1].ToString();
lstIndexList.DataValueField = dsIndexes.Tables[0].Columns[2].ToString();
lstIndexList.DataBind();
 lstIndexList.SelectedIndex = 0;

XML structure is as below

<?xml version="1.0" encoding="utf-8" ?>
<Indexes>
  <Index>
    <Index_ID Selected=true>01</Index_ID>
    <Index_Name>dfdfdfdsf</Index_Name>
    <Index_URL>dsdsfdfdf</Index_URL>
  </Index>
 <Index>
    <Index_ID Selected=false>02</Index_ID>
    <Index_Name>dfdfdfddererer</Index_Name>
    <Index_URL>dfsdfdfdfd</Index_URL>
  </Index>
</Indexes>
0
Comment
Question by:thirunachi
[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
  • 3
  • 2
5 Comments
 
LVL 13

Expert Comment

by:jeebukarthikeyan
ID: 18875765
hi,

if u want multiple items to be selected then set SelectionMode="Multiple"

and add the code after loading the item from xml

 foreach (ListItem li in ListBox1.Items)
        {
            li.Selected = true;
        }

thanks
b u d d h a
0
 

Author Comment

by:thirunachi
ID: 18880440
Receiving the following Error...
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS0117: 'System.Web.UI.WebControls.ListBox' does not contain a definition for 'items'

Source Error:

 

Line 84:                 lstIndexList.ToolTip = dsIndexes.Tables[0].Columns[3].ToString();
Line 85:                 lstIndexList.DataBind();
Line 86:                 foreach (listitem li in lstIndexList.items)
Line 87:                 {
Line 88:                     li.Selection = true;
 
0
 
LVL 13

Accepted Solution

by:
jeebukarthikeyan earned 500 total points
ID: 18880565
hi,

change the line
 foreach (listitem li in lstIndexList.items)

like this
 foreach (ListItem li in lstIndexList.Items)

b u d d h a
0
 

Author Comment

by:thirunachi
ID: 18880579
Thanks for the help....Why these properties dont show up in VS intellisense list members?  

Thanks
Thiru
0
 
LVL 13

Expert Comment

by:jeebukarthikeyan
ID: 18880588
hi,

seems problem with the vs

try pressing ctrl-space after a key word

b u d d h a
0

Featured Post

Industry Leaders: 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

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.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

733 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