Solved

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

Posted on 2007-04-09
5
1,240 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
  • 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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

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 …
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

758 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now