-
Andrew I downloaded you example but when I extracted the zip file and tried
to view the default aspx page there were error in displaying the list boxes.
Also the code is in C# I am using VB.So I clickend on the properties of the List Box in my project and when I
select the SelectedIndexChanged event in the controls properties there are
several selectionsdefaultPeremeterValuesList_SelectedIndexChanged
Page_Init
Page_Load
Redisplay_ClickWhich do I select?
Also I am only using a single selection from the first list box which is
bound to a SQL2008 Table to fill a second list box with items from a second
SQL2008 Table. Since both of the list boxes bound does the code change?
1 Solution
Hi David,
To accomplish this task you can handle the ASPxClientListBox.SelectedIndexChanged event for the first control and PerformCallback for the second control.
Please review the attached sample. It illustrates this approach in action.
-
Andrew I downloaded you example but when I extracted the zip file and tried to view the default aspx page there were error in displaying the list boxes. Also the code is in C# I am using VB.
So I clickend on the properties of the List Box in my project and when I select the SelectedIndexChanged event in the controls properties there are several selections
defaultPeremeterValuesList_SelectedIndexChanged
Page_Init
Page_Load
Redisplay_ClickWhich do I select?
-
Also Both of my listboxes and bound to SQL2008 Server Tables does this change your sample code?
-
Andrew, using VB, what I am trying to accomplish is this. I have one list box called PostList which contains a list of CWV Veterans Post i.e Post 1, Post 529, etc. I have a second list box ( SelectMembers) that contains a list of Member ID, Last Name, First Name, and Middle Name of members of the Posts.
When a Post number is selected in the PostList List box, I want the second List box to display only the members from the post number selected in the postlist listbox. As I mentioned earlier, -
Hi David,
I have attached a VB version of the sample to my original reply. Please review it.
It illustrates how to accomplish this task. -
Andrew I have attached a sample project containing the form I am working on. I made the changes you suggested, but I am getting errors on the list boxes now. Please look at my form and let me know what I am doing wrong. Also is there a way of making the project I am uploading private since I would not want the content to be public?
-
Hi David,
I apologize for the delayed response.
Please review the modified sample in the attachment. I have replaced the ListBox with the ASPxListBox and handled the client-side SelectionChanged event.
Check it and let us know your results. -
Andrew, please see the attached document. Unsing your revised project, I made changes to my code. The display errors went away bur when I select a post number from the PostList Listbox, it says it is loading but the DefaultParameter list box is not filled with the data from my 1st SQL datasource which I have linked to the 2nd Datasource which is the source of the PostList Listbox. Please advise.
-
Andrew just to clarify my previous comment, attached is a screen shot of where configeration for my sqldatasource1. I have it configured to link to the selected value of the postlist listbox. Would it be better if I used a dropdown listbox instead of the listbox?
-
Hi David,
Thank you for your feedback.
I have modified your sample to illustrate how to pass a parameter (via a session variable) to the DataSource for the second ASPxListBox. -
Andrew, I'm sorry for all the work I am causing you but I am confused. I looked at the code for the revised project and I don't see where you made the modification to pass a parameter (via a session variable) to the DataSource for the second ASPxListBox. Which is the DefaultParameterList AspxListbox and its datasourse id datasource1. Datasource2 is the datasource ID for the PostList aspxlistbox. I am assuming that the session varialble must be reset when the postno is selected in the postlist aspxlistbox control to update the datasource1. Could you please highlight the action I need to do this and the code I need to modify to set the session variable and have datasource1 refressed when the postno is selected in the postlist aspxlistbox.
-
Hi David,
Thank you for your feedback.
I save modified the SqlDataSource1 to request a parameter from the session variable :
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:CWVnatConnectionString %>" SelectCommand="SELECT [PKID], [Last], [First], [Middle], [PostNo] FROM [CWVMembers] WHERE ([PostNo] = @PostNo)"> <SelectParameters> <asp:SessionParameter DefaultValue="1" Name="PostNo" SessionField="PostNo" Type="Int32" /> </SelectParameters> </asp:SqlDataSource>and set this variable in the Callback event handler:
Protected Sub defaultParameterValuesList_Callback(sender As Object, e As DevExpress.Web.ASPxClasses.CallbackEventArgsBase) Handles defaultParameterValuesList.Callback Session("PostNo") = PostList.Items(Convert.ToInt32(e.Parameter)).Value.ToString() defaultParameterValuesList.DataBind() End SubI have attached a full sample for you, I hope it will help you accomplish your task. -
Andrew, I made the changes as you suggested as follows: <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:CWVnatConnectionString %>" SelectCommand="SELECT [PostNo], [Last], [First], [Middle], [PKID] FROM [CWVMembers] WHERE ([PostNo] = @PostNo)"> <SelectParameters> <asp:SessionParameter DefaultValue="1" Name="PostNo" SessionField="Post_Number" Type="Int32" /> </SelectParameters> </asp:SqlDataSource> Protected Sub defaultParameterValuesList_Callback(ByVal sender As Object, ByVal e As DevExpress.Web.ASPxClasses.CallbackEventArgsBase) Handles defaultParameterValuesList.Callback Session("Post_Number") = PostList.Items(Convert.ToInt32(e.Parameter)).Value.ToString() defaultParameterValuesList.DataBind() End Sub However the data in the defaultParameter List box is not changing when I make a selection. Please see the attached video that demos what is happening.
-
Hi David,
I see you are sending a callback to the incorrect ASPxListBox. You need to send it to the defaultParameterValuesList control:
<dx:ASPxListBox ID="PostList" runat="server" ClientInstanceName="defaultParameterValuesList" ClientIDMode="AutoID" DataSourceID="SqlDataSource2" TextField="Post_Number" ValueField="Post_Number"> <ClientSideEvents SelectedIndexChanged="function(s, e) { defaultParameterValuesList.PerformCallback(e.index); }" /> </dx:ASPxListBox> -
Andrew, I made the change you suggested above:
SelectCard.aspx Code:<%@ Page Language="VB" MasterPageFile="~/Default.master" AutoEventWireup="false" CodeFile="SelectCard.aspx.vb" Inherits="MemberCardSelect" title="Untitled Page" %> <%@ Register assembly="CrystalDecisions.Web, Version=12.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" namespace="CrystalDecisions.Web" tagprefix="CR" %> <%@ Register assembly="DevExpress.Web.ASPxEditors.v10.2, Version=10.2.6.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" namespace="DevExpress.Web.ASPxEditors" tagprefix="dx" %> <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"> <center> <b> <br /> Choose Post Number Then Click in the left checkbox for the Member ID's you wish to print!</b> <dx:ASPxListBox ID="PostList" runat="server" ClientInstanceName="defaultParameterValuesList" ClientIDMode="AutoID" DataSourceID="SqlDataSource2" TextField="Post_Number" ValueField="Post_Number" AutoPostBack="True"> <ClientSideEvents SelectedIndexChanged="function(s, e) { defaultParameterValuesList.PerformCallback(e.index); }" /> </dx:ASPxListBox> <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:CWVnatConnectionString %>" SelectCommand="SELECT [Post_Number] FROM [Posts] WHERE ([Department] = @Department) ORDER BY [Post_Number]"> <SelectParameters> <asp:Parameter DefaultValue="NY" Name="Department" Type="String" /> </SelectParameters> </asp:SqlDataSource> <dx:ASPxListBox ID="defaultParameterValuesList" runat="server" DataSourceID="SqlDataSource1" SelectionMode="CheckColumn" ValueField="PKID" TextField="PKID" Height="218px" Rows="10" ValueType="System.Int32" AutoPostBack="True"> <Columns> <dx:ListBoxColumn FieldName="PostNo" /> <dx:ListBoxColumn FieldName="Last" /> <dx:ListBoxColumn FieldName="First" /> <dx:ListBoxColumn FieldName="Middle" /> <dx:ListBoxColumn FieldName="PKID" /> </Columns> </dx:ASPxListBox> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:CWVnatConnectionString %>" SelectCommand="SELECT [PostNo], [Last], [First], [Middle], [PKID] FROM [CWVMembers] WHERE (([PostNo] = @PostNo) AND ([Deceased] = @Deceased)) ORDER BY [Last], [First], [Middle]"> <SelectParameters> <asp:SessionParameter DefaultValue="1" Name="PostNo" SessionField="PostNo" Type="Int32" /> <asp:Parameter DefaultValue="False" Name="Deceased" Type="Boolean" /> </SelectParameters> </asp:SqlDataSource> <asp:Button ID="redisplay" runat="server" Text="Click Here To Redisplay Report" Width="209px" /> <CR:CrystalReportViewer ID="CrystalReportViewer1" runat="server" AutoDataBind="True" GroupTreeImagesFolderUrl="" Height="918px" ReportSourceID="CrystalReportView1" ToolbarImagesFolderUrl="" ToolPanelWidth="200px" Width="1300px" EnableParameterPrompt="False" /> <CR:CrystalReportSource ID="CrystalReportView1" runat="server"> <Report FileName="SelectCWVMembershipCards.rpt"> </Report> </CR:CrystalReportSource> </center> </asp:Content>SelectCard.aspx.vb Code:
Imports Microsoft.VisualBasic Imports System Imports System.Data Imports System.Configuration Imports System.Collections Imports System.Web.UI.WebControls Imports System.Web.UI.WebControls.WebParts Imports CrystalDecisions.CrystalReports.Engine Imports CrystalDecisions.Shared Imports System.Collections.Generic Imports System.Text Imports System.Web.UI Imports DevExpress.Web.ASPxEditors Imports DevExpress.Web.ASPxGridView Imports System.Web Partial Class MemberCardSelect Inherits System.Web.UI.Page Private MemberCardReport As ReportDocument Private Const PARAMETER_FIELD_NAME As String = "MemberIDs" Private Sub SetTableLocation(ByVal tables As Tables) Dim connectionInfo As New ConnectionInfo() connectionInfo.ServerName = "Violet.Arvixe.com" connectionInfo.DatabaseName = "CWVNat" connectionInfo.UserID = "pgkdave" connectionInfo.Password = "kc11449" For Each table As CrystalDecisions.CrystalReports.Engine.Table In tables Dim tableLogOnInfo As TableLogOnInfo = table.LogOnInfo tableLogOnInfo.ConnectionInfo = connectionInfo table.ApplyLogOnInfo(tableLogOnInfo) Next End Sub Private Sub ConfigureCrystalReports() MemberCardReport = New ReportDocument() Dim reportPath As String = Server.MapPath("SelectCWVMembershipCards.rpt") MemberCardReport.Load(reportPath) SetTableLocation(MemberCardReport.Database.Tables) Dim myArrayList As ArrayList = New ArrayList() If Not IsPostBack Then Session("myArrayList") = myArrayList Else myArrayList = CType(Session("myArrayList"), ArrayList) End If SetCurrentValuesForParameterField(MemberCardReport, myArrayList) CrystalReportViewer1.ReportSource = MemberCardReport End Sub Private Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init ConfigureCrystalReports() End Sub Private Sub SetCurrentValuesForParameterField(ByVal myReportDocument As ReportDocument, ByVal myArrayList As ArrayList) Dim currentParameterValues As ParameterValues = New ParameterValues() For Each submittedValue As Object In myArrayList Dim myParameterDiscreteValue As ParameterDiscreteValue = New ParameterDiscreteValue() myParameterDiscreteValue.Value = submittedValue.ToString() currentParameterValues.Add(myParameterDiscreteValue) Next Dim myParameterFieldDefinitions As ParameterFieldDefinitions = myReportDocument.DataDefinition.ParameterFields Dim myParameterFieldDefinition As ParameterFieldDefinition = myParameterFieldDefinitions(PARAMETER_FIELD_NAME) myParameterFieldDefinition.ApplyCurrentValues(currentParameterValues) End Sub Private Function GetDefaultValuesFromParameterField(ByVal myReportDocument As ReportDocument) As ArrayList Dim myParameterFieldDefinitions As ParameterFieldDefinitions = myReportDocument.DataDefinition.ParameterFields Dim myParameterFieldDefinition As ParameterFieldDefinition = myParameterFieldDefinitions(PARAMETER_FIELD_NAME) Dim defaultParameterValues As ParameterValues = myParameterFieldDefinition.DefaultValues Dim myArrayList As ArrayList = New ArrayList() For Each myParameterValue As ParameterValue In defaultParameterValues If (Not myParameterValue.IsRange) Then Dim myParameterDiscreteValue As ParameterDiscreteValue = CType(myParameterValue, ParameterDiscreteValue) myArrayList.Add(myParameterDiscreteValue.Value.ToString()) End If Next Return myArrayList End Function Protected Sub redisplay_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles redisplay.Click Dim myArrayList As ArrayList = New ArrayList() For Each item As ListEditItem In defaultParameterValuesList.Items If item.Selected Then myArrayList.Add(item.Value) End If Next Session("myArrayList") = myArrayList ConfigureCrystalReports() End Sub Protected Sub defaultPeremeterValuesList_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles defaultParameterValuesList.SelectedIndexChanged End Sub Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load, PostList.SelectedIndexChanged End Sub Protected Sub PostListValuesList_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) End Sub Protected Sub defaultParameterValuesList_Callback(ByVal sender As Object, ByVal e As DevExpress.Web.ASPxClasses.CallbackEventArgsBase) Handles defaultParameterValuesList.Callback Session("PostNo") = PostList.Items(Convert.ToInt32(e.Parameter)).Value.ToString() defaultParameterValuesList.DataBind() End Sub Protected Sub defaultParameterValuesList_Callback(ByVal sender As Object, ByVal e As System.EventArgs) End Sub End ClassHowever, the data in the defaultPaarameterValueList still is not changing. See video attached!
-
Andrew just out of curiosity, can what I am trying to do with this form be accomplished easier using your gridview with filtering and xtrareports instead of Crystal Reports? Please see the attached video and let me know.
-
Hi David,
>> However, the data in the defaultPaarameterValueList still is not changing.
Your project does not work correctly because the "PostList" ListBox's AutoPostBack property is set to the true value. Set it to "false" to process the SelectedIndexChanged event on the client side.
Sending the selected item index as a callback parameter is also not completely correct, because it is necessary to send an item's value to assign it to the session field on the server. As ListBox is in the single item selection mode, you can use its client-side GetValue method to get the selected item's value. On the server side, use the ASPxListBox.DataBindItems method to bind the ASPxListBox control.I have created a sample project demonstrating how you can implement your behavior using the ASPxListBox or ASPxGridView controls. You can find it in the attachment.
The sample project consists of two web forms:
1) The "ListBox" web form demonstrates how you can solve your task using ASPxListBox controls.
2) The "GridView" web form demonstrates how you can solve your task using ASPxGridVierw control with filtering.
To filter ASPxGridView on the client side, I have used its ASPxClientGridView.ApplyFilter method.>> Andrew just out of curiosity, can what I am trying to do with this form be accomplished easier using your gridview with filtering and xtrareports instead of Crystal Reports? Please see the attached video and let me know.
Our team is dedicated to addressing all your concerns. In order to better serve you and track multiple questions from your inquiry, we have taken the liberty of separating the issues you addressed. For quick and efficient responses to your concerns, we kindly request that future inquiries address one issue at a time. I have extracted this question to a separate ticket created on your behalf: Q407762(<sclink id="Q285871">).
P.S. You can downgrade / upgrade the sample project I provided via the Project Converter tool. Take a look at the Upgrade Notes help topic to learn more about downgrade / upgrade procedures.
Is your intention to post an answer to your own question?
- If so, then proceed.
- If you simply wanted to post additional information, ask for further clarification, or to just say "Thanks!", please click Leave a Comment.
- If you wish to edit your original question, please use the Edit button in the Toolbox at the top right corner of that entry.