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?
In my VS 2017, I right-clicked on Project (WebDropDownSample), then clicked Manage NuGet Packages and in the dialog searched for and found Microsoft.CodeDom.Providers.DotNetCompilerPlatform and VS told me it was already installed.
Microsoft.CodeDom.Providers.DotNetCompilerPlatform and VS told me it was already installed.
Can you check if the versions of the package you have already installed is the same as the one referenced in the web.config file
<compilers> <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.8.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:1659;1699;1701" /> <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.8.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:41008 /define:_MYTYPE=\"Web\" /optionInfer+" /> </compilers>
The web.config you posted above shows Version 1.0.8.0 BUT the one inside the .zip file you provided shows Version 1.0.0.0. In my Manage NuGet Packages, it shows 1.0.0 is installed. By the way, the project shows about 25 other errors related to styles and modules in the App_Code folder.
OK, may be it will be easier if I post the code so that you copy it on your own project and try to run it
Default.aspx file
<%@ Page Title="Home Page" Language="VB" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeFile="Default.aspx.vb" Inherits="_Default" %><%@ Register Assembly="Infragistics45.Web.v19.1, Version=19.1.20191.115, Culture=neutral, PublicKeyToken=7dd5c3163f2cd0cb" Namespace="Infragistics.Web.UI.ListControls" TagPrefix="ig" %>
<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server"> <ig:WebDropDown ID="WebDropDown1" runat="server" Width="200px" EnableMultipleSelection="true"></ig:WebDropDown> <asp:Button ID="Button1" runat="server" Text="Button" /></asp:Content>
Default.aspx.vb file
Imports SystemImports System.WebImports Infragistics.Web.UI.ListControls
Partial Class _Default Inherits Page Sub Page_Load(ByVal Sender As Object, ByVal e As EventArgs) Dim service As New MyWebService() WebDropDown1.DataSource = service.GetDaysOfTheWeek() End Sub
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click Dim s As String s = WebDropDown1.SelectedItems(0).Text Dim items = WebDropDown1.SelectedItems End SubEnd Class
MyWebService.vb
Imports System.WebImports System.Web.ServicesImports System.Web.Services.Protocols
Public Class MyWebService Inherits System.Web.Services.WebService
<WebMethod()> Public Function GetDaysOfTheWeek() As String() Dim weekdays As String() = New String() {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"} Return weekdays End Function
End Class
Well, I'd have to install the service, etc to get everything working and deal with any issues. Still would be time consuming I believe.
Can't we troubleshoot what I posted? The only part not working is in the code-behind accessing the selected items. What are the possible reasons the list would not be accessible?
Do you work for Infragistics? If so, can we have a phone call and a quick goto meeting?