?
Solved

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

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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses

850 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