Solved

Check Select Checkboxes in Panel

Posted on 2011-09-26
6
262 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
  • 4
  • 2
6 Comments
 
LVL 12

Expert Comment

by:jagssidurala
Comment Utility
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
Comment Utility
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
Comment Utility
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 1

Author Comment

by:jshesek
Comment Utility
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
Comment Utility
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
Comment Utility
I found the solution myself
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Please explain: Aspect Oriented Programming 2 50
ASP.Net Session State alternatives 3 25
JavaScript error 1 32
Create XML 5 30
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

762 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now