Solved

Check Select Checkboxes in Panel

Posted on 2011-09-26
6
271 Views
Last Modified: 2012-05-12
There's a page that displays 1 case for edit.  Every case has a state or states hooked up to it.  There is a label that shows all the state(s) that are with that case.  The page also has a panel that displays a checkbox for all the US states.  When the user clicks on the Modify List button the panel shows.  I'm trying to get those state(s), attached to the case, to display with the checkboxes checked.  

Here's the aspx page:

<%@ Page Title="" Language="VB" MasterPageFile="~/Masters/mstrIntranet.master" AutoEventWireup="false" CodeFile="CaseModify.aspx.vb" Inherits="Tools_Case_Modify" MaintainScrollPositionOnPostBack="True"%>

<asp:Content ID="Content1" ContentPlaceHolderID="contentplaceholder2" Runat="Server">
        <form id="Form1" name="form1" method="post" runat="server">
    <table cellpadding="0" cellspacing="0" class="text" border="0"
        style="width: 693px;">
        <tr valign="top">
            <td style="width: 174px" >
                &nbsp;</td>
            <td height="24" colspan="3" >
                &nbsp;</td>
        </tr>
            <tr>
            <td style="width: 174px">States</td>
            <td colspan="3">
                <asp:Label ID="lblStates" runat="server" CssClass="text"></asp:Label>
                <asp:Button ID="btnModifyList" runat="server" Text="Modify List" />
            </td>
        </tr>
         <tr>
            <td colspan="4">
                <asp:Panel ID="pnlStates" runat="server">
                <asp:DataList ID="dlStates" runat="server" RepeatDirection="Horizontal" RepeatColumns="4"
                EnableViewState="True" Width="623px">
                   <ItemTemplate>
                      <asp:CheckBox ID="chkStateID" runat="server" Text='<%# Eval("State") %>' />
                    </ItemTemplate>  
                   </asp:DataList>
                    <div align="right">
                        <asp:Button ID="btnForeign" runat="server" Text="Show Foreign" />
                        &nbsp;&nbsp;&nbsp;
                        <asp:Button ID="btnCloseStates" runat="server" Text="Hide States" />
                    </div>
                    <hr></hr>
                </asp:Panel> <p>                                                  
                    &nbsp;<asp:Panel ID="pnlStatesF" runat="server">
                <asp:DataList ID="dlStatesF" runat="server" RepeatDirection="Horizontal" RepeatColumns="4"
                EnableViewState="True" Width="655px">
                   <ItemTemplate>
                      <asp:CheckBox ID="chkStateID" runat="server" Text='<%# Eval("State") %>' />
                    </ItemTemplate>  
                   </asp:DataList><p><div align="right">
                <asp:Button ID="btnCloseForeign" runat="server" Text="Hide Foreign" align="right"/></div>
                </asp:Panel>
                &nbsp;</td>
        </tr>
        <tr>
            <td style="width: 174px">&nbsp;</td>
            <td colspan="2">&nbsp;</td>
            <td>&nbsp;<asp:Button ID="btnUpdate" runat="server" Text="Update" />
                <asp:Button ID="btnCancel" runat="server" Text="Cancel" />
            </td>
        </tr>
    </table>
    </form>
</asp:Content>

Here's the aspx.vb page:

Imports Microsoft.VisualBasic
Imports System.Data
Imports System.Data.OleDb
Imports AreaNameNumber
Imports Cases
Imports States_All

Partial Class Tools_Case_Modify
    Inherits System.Web.UI.Page
    Public dr As OleDbDataReader
    Public ds As DataSet

    Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
        Dim strSQL As String
        Dim dsStates As DataSet
        Dim dRow As DataRow

        If Not (Page.IsPostBack) Then
            Dim thisID, thisType As Integer
            thisID = Request.QueryString("j")
            lbl1.Text = thisID

            strSQL = "SELECT * "
            strSQL = strSQL + "FROM Cases"
            strSQL = strSQL + "WHERE (Cases.caseID = " & thisID & ")"

            ds = Cases.GetData(strSQL)

            dsStates = Cases.GetData("Select * FROM RelatedStates WHERE caseID = '" & thisID & "' ORDER BY RelatedState")

            '~~~~~~~~~~ Panel for States
            dlStates.DataSource = States_All.GetData("Select  *  From StateForeignCodes WHERE Foreign = False ORDER BY State")
            dlStates.DataBind()

            For Each dRow In dsStates.Tables(0).Rows
                lblStatesInvolved.Text = lblStatesInvolved.Text & dsStates.Tables(0).Rows(0).Item("relatedState") & ", "
            Next

            pnlStates.Visible = False
            btnForeign.Visible = False
            btnCloseStates.Visible = False

                     
            '~~~~~~~~~~~ Panel for Foreign States
            dlStatesF.DataSource = States_All.GetData("Select  *  From StateForeignCodes WHERE Foreign = True ORDER BY State")
            dlStatesF.DataBind()
            pnlStatesF.Visible = False

            dsAlerts = MajorCases.GetData("Select * FROM addlInfo WHERE caseID = " & thisID & "")
            For Each dRow In dsAlerts.Tables(0).Rows
                lblCaseAlerts.Text = lblCaseAlerts.Text & dsAlerts.Tables(0).Rows(0).Item("info") & ", "
            Next

        End If
    End Sub

    Protected Sub btnModifyList_Click(sender As Object, e As System.EventArgs) Handles btnModifyList.Click
        pnlStates.Visible = True
        btnForeign.Visible = True
        btnCloseStates.Visible = True
        btnModifyList.Visible = False

    End Sub

    Protected Sub btnForeign_Click(sender As Object, e As System.EventArgs) Handles btnForeign.Click
        pnlStatesF.Visible = True
        btnCloseForeign.Visible = True
    End Sub

    Protected Sub btnCloseForeign_Click(sender As Object, e As System.EventArgs) Handles btnCloseForeign.Click
        pnlStatesF.Visible = False
        btnCloseForeign.Visible = False
    End Sub

    Protected Sub btnCloseStates_Click(sender As Object, e As System.EventArgs) Handles btnCloseStates.Click
        btnModifyList.Visible = True
        btnCloseForeign.Visible = False
        btnCloseStates.Visible = False
        pnlStates.Visible = False

    End Sub
End Class

 Before with label2.JPG
0
Comment
Question by:jshesek
[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
  • 4
  • 2
6 Comments
 
LVL 12

Expert Comment

by:jagssidurala
ID: 36600554
I hope this code will helps you

foreach (DataListItem item in dlStates.Items) {
      CheckBox chkStateID= (CheckBox)item.FindControl("chkStateID");            
      if(chkStateID != null & chkStateID.checked)
      {
      }
}

based on the panel visibility you need to retrieve from different datalist.........
0
 
LVL 1

Author Comment

by:jshesek
ID: 36600917
Thanks for the quick reply.  
This is where I pull the states that belong to a case.

dsStates = Cases.GetData("Select * FROM RelatedStates WHERE caseID = '" & thisID & "' ORDER BY RelatedState")
            For Each dRow In dsStates.Tables(0).Rows
                lblStatesInvolved.Text = lblStatesInvolved.Text & dsStates.Tables(0).Rows(0).Item("relatedState") & ", "
            Next

This is where I populate the panel.

dlStates.DataSource = States_All.GetData("Select  *  From StateForeignCodes WHERE Foreign = False ORDER BY State")
            dlStates.DataBind()

So in this case lets say only Iowa is attached to the case.  When the panel shows only want Iowa should be checked.  I think your example would check them all?
0
 
LVL 12

Expert Comment

by:jagssidurala
ID: 36600979
Are you storing the checked values in the Database. if so, while retrieving if matches(some where you have to joins for your tables) with saved data get true as another column(Lets say column name as stateChecked) in the result set and assign the same column to the checkbox in the datalist like below.

<ItemTemplate>
                      <asp:CheckBox ID="chkStateID" runat="server" Text='<%# Eval("State") %>'
Checked='<%# Eval("stateChecked") %>'
 />
                    </ItemTemplate>  
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:jshesek
ID: 36601555
Yes the states that apply to the case are in a different table.  
If I set the panel of checkboxes all the states up first
When I do this:
 For Each dRow In dsStates.Tables(0).Rows
                lblStatesInvolved.Text = lblStatesInvolved.Text & dsStates.Tables(0).Rows(0).Item("relatedState") & ", "

            Next

Is there some type of findControl I can do?  The checkbox value would be the state abbreviation that's in the separate table.
0
 
LVL 1

Accepted Solution

by:
jshesek earned 0 total points
ID: 36711517
Found the answer:  The database that holds the case states has it as abbreviated.  The checkboxes have the full state name.  So they never match to check off.  
What I did was add the state abbreviation in at the end enclosed in ().  Then pulled out the abbreviation to check for a match.  

Here's the code from the aspx page:
 <asp:DataList ID="dlStates" runat="server" RepeatDirection="Horizontal" RepeatColumns="4" EnableViewState="True" Width="682px">
       <ItemTemplate>
          <asp:CheckBox ID="chkStateID" runat="server" Text='<%# Eval("State") & " (" & Eval("State_ID") & ")"%>' />
        </ItemTemplate>  
  </asp:DataList>

Here's the code from the aspx.vb page:dlStates.DataBind()
 Dim checkBox As CheckBox
 Dim x As String

 For Each dRow In dsStates.Tables(0).Rows
     lblStatesInvolved.Text = lblStatesInvolved.Text & dRow.Item("relatedState") & ", "

     For Each dlitme In dlStates.Items
         checkBox = DirectCast(dlitme.FindControl("chkStateID"), CheckBox)

         x = Right(checkBox.Text, 3)
         x = Left(x, 2)

         If (x = dRow.Item("relatedState")) Then
             checkBox.Checked = True
         End If
     Next
 Next
0
 
LVL 1

Author Closing Comment

by:jshesek
ID: 36935222
I found the solution myself
0

Featured Post

Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

Question has a verified solution.

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

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

756 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