?
Solved

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

Posted on 2007-04-09
5
Medium Priority
?
1,252 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 1500 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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!
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.
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.…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

777 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