Solved

Filtering CheckBoxList datasource problem

Posted on 2011-09-12
3
485 Views
Last Modified: 2012-05-12
Hello Experts,

I have a page where I have a CheckBoxList Control set to a default SelectCommand in my ASPX page, I am using a RadioButtonList to filter the return values by changing the SelectCommand on the SelectedIndexChanged event. In the code-behind, I am using it like so;
If RadioButtonList1.SelectedValue = 1 Then
            SqlDataSource1.SelectCommand = "SELECT [id], [Prod_Name]...
            SqlDataSource1.DataBind()
        ElseIf RadioButtonList1.SelectedValue = 2 Then
            SqlDataSource1.SelectCommand = "SELECT [id], [Prod_Name]...
            SqlDataSource1.DataBind()
        ElseIf RadioButtonList1.SelectedValue = 3 Then
            SqlDataSource1.SelectCommand = "SELECT [id], [Prod_Name]...
            SqlDataSource1.DataBind()...

End If

On a ButtonClick Event the CheckBoxList.SelectedItem.Text  is written to another table in the database.

My problem is although the filtering does work on the radiobutton selection (the CheckBoxList control values are filtered properly in both html return and source-view), the insert will always
use the default list that was originally loaded at initial runtime.
How do I correct this?

I have tried Dim CheckBoxList1 As New CheckBoxList in various places to no avail.

Thanks!
0
Comment
Question by:Phosphor
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 18

Accepted Solution

by:
ivan_vagunin earned 500 total points
ID: 36524542
Hi! You should save SelectCommand in ViewState - if you want to save filtering between postbacks and in SessionState if you want to save filtering all session long.

If RadioButtonList1.SelectedValue = 1 Then
            SqlDataSource1.SelectCommand = "SELECT [id], [Prod_Name]...
            SqlDataSource1.DataBind()
        ElseIf RadioButtonList1.SelectedValue = 2 Then
            SqlDataSource1.SelectCommand = "SELECT [id], [Prod_Name]...
            SqlDataSource1.DataBind()
        ElseIf RadioButtonList1.SelectedValue = 3 Then
            SqlDataSource1.SelectCommand = "SELECT [id], [Prod_Name]...
            SqlDataSource1.DataBind()...
End If
ViewState("MySelectCommand") = SqlDataSource1.SelectCommand

then you should init SqlDataSource1.SelectCommand in OnLoad Event (indeed OnLoad fires before event handlers, so if user changes the selection SelectCommand will be overwritten)
Protected Sub OnLoad(ByVal e As EventArgs)
     SqlDataSource1.SelectCommand = CType(ViewState("MySelectCommand"),String)
End Sub

0
 
LVL 1

Author Comment

by:Phosphor
ID: 36524992
Actually what ended up working was changing the checkboxlist viewstate property from false to true.

Thank you for your response as it did eventually lead to resolution.
0
 
LVL 1

Author Closing Comment

by:Phosphor
ID: 36525012
It's working now as intended and your answer got me to thinking about viewstate in general which I hadn't yet considered.

Thanks again.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

691 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