Solved

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

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

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

688 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