473,401 Members | 2,139 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,401 software developers and data experts.

Set Selected Listbox Items From SqlDataSource

cmmitw
4
I have a multiselect enabled listbox on the page that is populated from a SqlDataSource.

I have another DataSource that retrieves the selected items from the database.

I cannot for the life of me figure out how to set all of the selected items in the listbox.

I have figured out how to get the first item from the selected items sqldatasource, but I don't know how to set ALL of the items from the sqldatasource as selected.

Any help would be greatly appreciated. I have been working on this for 3 days now to no avail.

Here is my listbox, sqlqueries, and code:

Expand|Select|Wrap|Line Numbers
  1. <telerik:RadListBox ID="Regions_RadListBox" runat="server" Width="200px" 
  2.              SelectionMode="Multiple" Rows="3" TextMode="MultiLine" DataSortField="Region" 
  3.              DataSourceID="Regions_SqlDataSource" DataTextField="Region" 
  4.              DataValueField="RegionID" Height="60px">
  5. </telerik:RadListBox>
  6.  

Expand|Select|Wrap|Line Numbers
  1. <asp:SqlDataSource ID="Regions_SqlDataSource" runat="server" 
  2.     ConnectionString="<%$ ConnectionStrings:SiteSqlServer %>" 
  3.     SelectCommand="SELECT [RegionID], [Region] FROM [NC_CT_Regions]"></asp:SqlDataSource>
  4.  
  5. <asp:SqlDataSource ID="SelectedRegions_SqlDataSource" runat="server" 
  6.     ConnectionString="<%$ ConnectionStrings:SiteSqlServer %>" 
  7.     SelectCommand="SELECT PreferenceValue FROM NC_EmployeePreference WHERE PreferenceTypeID = '4' AND EmpID = @EmpID">
  8.     <SelectParameters>
  9.         <asp:QueryStringParameter Name="EmpID" QueryStringField="EmpID" />
  10.     </SelectParameters>
  11. </asp:SqlDataSource>

Expand|Select|Wrap|Line Numbers
  1. Dim regionsSql As DataView = DirectCast(SelectedRegions_SqlDataSource.Select(DataSourceSelectArguments.Empty), DataView)
  2.         For Each regionsviewSql As DataRowView In regionsSql
  3.             If Not Page.IsPostBack And regionsviewSql("PreferenceValue").ToString <> "" Then
  4.                 Regions_RadListBox.SelectedValue = regionsviewSql("PreferenceValue")
  5.             End If
  6.         Next
Jan 21 '10 #1
4 5221
For the line in your if statement, try selecting this way:

Regions_RadListBox.Items(Regions_RadListBox.Items. IndexOf(regionsviewSql("PreferenceValue"))).Select ed = True

That way it just finds that item in the listbox, and selects it.
Jan 21 '10 #2
cmmitw
4
It tells me:

'Telerik.Web.UI.ControlItemCollection.Protected Friend Overridable Function IndexOf(item As Telerik.Web.UI.ControlItem) As Integer' is not accessible in this context because it is 'Protected Friend'.

and hilights this section of code:

Regions_RadListBox.Items.IndexOf
Jan 21 '10 #3
This may not be the most efficient way, but you can try this in your if

For each item as Telerik.Web.UI.ControlItem In Regions_RadListBox.Items
If item.ToString() = regionsviewSql("PreferenceValue")
item.selected = True
End If
Next
Jan 21 '10 #4
cmmitw
4
Apparently:

'Selected' is not a member of 'Telerik.Web.UI.ControlItem'

I tried 'ListItem' instead, and the error went away, but nothing got selected in the box.

I appreciate your help on this!
Jan 21 '10 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Peter Moscatt | last post by:
I am having trouble understanding the methods for the Listbox from Tk. If I was to select at item in the list using a mouse click (have already created the bind event) - what method returns the...
8
by: Vipin Kedia | last post by:
Hi I have written a code for showing the list boxes as selected using a Listitem and the selected property of the items. Now I have 2 list boxes in my page. But it shows only the selected values...
2
by: Geir Baardsen | last post by:
Hi! From a listbox I'd like to send only selected items to a report. Items will include: OrderNr,Date,EmployeeNr from tblOrders ZipCode,City from tblZipCodes Name,Adr,ZipID from...
2
by: JP | last post by:
Hi, I am trying to loop through the listbox and read the selected items from the list, within a CLICK event on an aspx page. The following is what I have tried. It loops through the listbox,...
3
by: Richard Albrecht | last post by:
I have been trying to figure out for days on how to read values from a Bound ListBox. The listBox gets the values from an Access Table. I can read values fine for Non-Bound ListBoxes, But the...
2
by: Srimadhi | last post by:
Displaying selected items at the top of the listbox Hi, I am having two listboxes - one with ids and second with the related names. When user selects an item in one listbox, the corresponding...
2
by: John | last post by:
I have a listbox that is databound when my form loads. A user can then select and option using a drop down box. When the user selects an option the corresponding items in the listbox gets selected....
2
by: Hitesh | last post by:
I have a listbox and the values get selected (highlighted) from code. I can highlight the corresponding list box items, but they do not show in the listbox I have to scroll through the list box to...
3
by: Mitch | last post by:
Is the following a correct representation of the relationship of the selected index to selected item: INDEX ITEM 0 "item 1" 1 "item 2" 2 "item 3" and so on. I keep...
4
by: rn5a | last post by:
I am binding a DropDownList with records existing in a database table. I want to add an extra item *SELECT COMPANY* at index 0 so that by default, it gets selected. This is how I tried it but the...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.