Hello,
I have a webform with a WebDropDown on it configured for checkbox multi-select based. It functions fine when the web form is running (no javascript errors). I am having difficulty accessing the selected items on server-side that were checked in the control.
My aspx page markup is:
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="InfraTest.aspx.vb" Inherits="ReferralConnect.InfraTest" %>
<%@ Register assembly="Infragistics45.Web.v19.1, Version=19.1.20191.115, Culture=neutral, PublicKeyToken=7dd5c3163f2cd0cb" namespace="Infragistics.Web.UI.ListControls" tagprefix="ig" %>
<!DOCTYPE html>
<html xmlns="">www.w3.org/.../xhtml"><head runat="server"> <title></title></head><body> <script type="text/javascript">
function selectedIndexChanging(sender, eventArgs) { var oldItems = eventArgs.getOldSelection(); var newItems = eventArgs.getNewSelection();
var oldItemsString= ""; var newItemsString= "";
for (i = 0; i < oldItems.length; i++) { if (oldItems[i] != null) oldItemsString += oldItems[i].get_index() + ", "; }
for (i = 0; i < newItems.length; i++) newItemsString += newItems[i].get_index() + ", ";
addLine('<%= GetGlobalResourceObject("ddlServices", "MultiSelectionSelectionChanging") %>' + "(" + sender.get_name() + "): " + '<%= GetGlobalResourceObject("ddlServices", "MultiSelectionOldItems") %>' + " = [ " + oldItemsString + " ] ; " + '<%= GetGlobalResourceObject("ddlServices", "MultiSelectionNewItems") %>' + " = [ " + newItemsString + " ]; "); }
function selectedIndexChanged(sender, eventArgs) { var oldItems = eventArgs.getOldSelection(); var newItems = eventArgs.getNewSelection();
addLine('<%= GetGlobalResourceObject("ddlServices", "MultiSelectionSelectionChanged") %>'+ "(" + sender.get_name() + "): " + '<%= GetGlobalResourceObject("ddlServices", "MultiSelectionOldItems") %>' + " = [ " + oldItemsString + " ] ; " + '<%= GetGlobalResourceObject("ddlServices", "MultiSelectionNewItems") %>' + " = [ " + newItemsString + " ]; "); } </script>
<form id="form1" runat="server"> <div> <%= GetGlobalResourceObject("ddlServices", "MultiSelectionCheckbox") %><br /><br /><ig:WebDropDown runat="server" ID="ddlServices" EnableClosingDropDownOnSelect="False" TextField="ServiceName" Width="400px" DropDownContainerHeight="300px" EnableMultipleSelection="True" Enabled="True" ViewStateMode="Inherit"><ClientEvents SelectionChanged="selectedIndexChanged" SelectionChanging="selectedIndexChanging" /></ig:WebDropDown> <asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager>
<br /> <asp:Button ID="Button1" runat="server" Text="Button" />
</div> </form></body></html>
My code behind (VB is):
Imports SystemImports System.DataImports System.Data.SqlClientImports System.Data.SqlTypesImports System.IO
Public Class InfraTest Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load 'Load Services into Dropdown. Dim SqlConnection1 As New SqlConnection(ConfigurationManager.ConnectionStrings("INSTANCE").ConnectionString) Dim SQLString As String SQLString = "select ServiceName, ServiceID from ProviderServices where ProviderID = " + "'" + "1" + "'" SQLString = SQLString + " order by ServiceName" Dim dtSelected As DataTable
Try Dim daSelected As SqlDataAdapter = New SqlDataAdapter(SQLString, SqlConnection1) dtSelected = New DataTable() daSelected.Fill(dtSelected) ddlServices.DataSource = dtSelected
Catch ex As Exception Return End Try
End Sub
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click Dim S2 As String S2 = ddlServices.SelectedItems(0).Text
Dim test As Integer test = ddlServices.SelectedItems.Count
Dim wdd As Infragistics.Web.UI.ListControls.WebDropDown = DirectCast(Page.FindControl("ddlServices"), Infragistics.Web.UI.ListControls.WebDropDown) Dim items As List(Of Infragistics.Web.UI.ListControls.DropDownItem) = wdd.SelectedItems Dim cnt As Integer = 0 cnt = items.Count Dim test1 As Integer test1 = 0 End SubEnd Class
ddlServices.SelectedItems(0).Text throws an out of range exception even though some values in the dropdown list are checked.
ddlServices.SelectedItems.Count is equla to 0
The findcontrol method doesn't work eithor.
Perhaps I'm misunderstanding something. I want to access the list of checked items so I can do some processing on them on the server side after a button is clicked.
My viewstate is enabled.
Any advice?
Hi Stewart,
I tried to reproduce the behavior you are describing and I created a simple project with the WebDropDown. My project uses NetAdvantage for .NET Version=19.1.20191.115. When clicking the button, it gets the selected items in the drop down.I have attached the sample project I used to test this. Please test this project on your PC; whether or not it works correctly may help indicate the nature of this problem.
If the project does show the product feature working correctly, then more information will be needed to reproduce the issue in a sample that can be used for debugging. It will help if you can provide a small, isolated sample application that demonstrates the behavior you are seeing. This can be done by either making the sample that I provided more like your application or by isolating the behavior from your application by removing dependencies on any third parties or databases.
Please let me know if I can provide any further assistance.
WebDropDownSample.zip
Can you please include the solution file?
Count still shows 0.
Can you please answer these two questions:
Do you work for Infragistics? If so, can we have a phone call and a quick goto meeting?
Remotely debugging your application is beyond the scope of what developer support provides. Please review the provided sample to see what is different between your application and the sample and use that as a guide for updating your application or modify the sample so it is a more accurate representation of your application and I will assist you within context of the sample.
OK, understood.
I solved my issue by removing everything from the infragistics sample https://es.infragistics.com/samples/aspnet/drop-down/multi-selection
and dropping in a clean webdropdown control, no scripts, no extra markup. Now it works.
I am glad you were able to resolve your issue.
Please feel free to contact us if you have any question about our products.
I am thinking that the javascript in the example on your documentation page, removes items from selected items list as it populates the textbox control leaving us with an empty list. That's just a guess. I haven't analyzed it.