JS List
asked on
Check Select Checkboxes in Panel
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/ mstrIntran et.master" AutoEventWireup="false" CodeFile="CaseModify.aspx. vb" Inherits="Tools_Case_Modif y" MaintainScrollPositionOnPo stBack="Tr ue"%>
<asp:Content ID="Content1" ContentPlaceHolderID="cont entplaceho lder2" 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" >
</td>
<td height="24" colspan="3" >
</td>
</tr>
<tr>
<td style="width: 174px">States</td>
<td colspan="3">
<asp:Label ID="lblStates" runat="server" CssClass="text"></asp:Labe l>
<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="Horizonta l" 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" />
<asp:Button ID="btnCloseStates" runat="server" Text="Hide States" />
</div>
<hr></hr>
</asp:Panel> <p>
<asp:Panel ID="pnlStatesF" runat="server">
<asp:DataList ID="dlStatesF" runat="server" RepeatDirection="Horizonta l" 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>
</td>
</tr>
<tr>
<td style="width: 174px"> </td>
<td colspan="2"> </td>
<td> <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("rel atedState" ) & ", "
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("inf o") & ", "
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(send er As Object, e As System.EventArgs) Handles btnCloseForeign.Click
pnlStatesF.Visible = False
btnCloseForeign.Visible = False
End Sub
Protected Sub btnCloseStates_Click(sende r 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
2.JPG
Here's the aspx page:
<%@ Page Title="" Language="VB" MasterPageFile="~/Masters/
<asp:Content ID="Content1" ContentPlaceHolderID="cont
<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" >
</td>
<td height="24" colspan="3" >
</td>
</tr>
<tr>
<td style="width: 174px">States</td>
<td colspan="3">
<asp:Label ID="lblStates" runat="server" CssClass="text"></asp:Labe
<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="Horizonta
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" />
<asp:Button ID="btnCloseStates" runat="server" Text="Hide States" />
</div>
<hr></hr>
</asp:Panel> <p>
<asp:Panel ID="pnlStatesF" runat="server">
<asp:DataList ID="dlStatesF" runat="server" RepeatDirection="Horizonta
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>
</td>
</tr>
<tr>
<td style="width: 174px"> </td>
<td colspan="2"> </td>
<td> <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
dlStates.DataBind()
For Each dRow In dsStates.Tables(0).Rows
lblStatesInvolved.Text = lblStatesInvolved.Text & dsStates.Tables(0).Rows(0)
Next
pnlStates.Visible = False
btnForeign.Visible = False
btnCloseStates.Visible = False
'~~~~~~~~~~~ Panel for Foreign States
dlStatesF.DataSource = States_All.GetData("Select
dlStatesF.DataBind()
pnlStatesF.Visible = False
dsAlerts = MajorCases.GetData("Select
For Each dRow In dsAlerts.Tables(0).Rows
lblCaseAlerts.Text = lblCaseAlerts.Text & dsAlerts.Tables(0).Rows(0)
Next
End If
End Sub
Protected Sub btnModifyList_Click(sender
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(send
pnlStatesF.Visible = False
btnCloseForeign.Visible = False
End Sub
Protected Sub btnCloseStates_Click(sende
btnModifyList.Visible = True
btnCloseForeign.Visible = False
btnCloseStates.Visible = False
pnlStates.Visible = False
End Sub
End Class
2.JPG
ASKER
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("rel atedState" ) & ", "
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?
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)
Next
This is where I populate the panel.
dlStates.DataSource = States_All.GetData("Select
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?
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>
<ItemTemplate>
<asp:CheckBox ID="chkStateID" runat="server" Text='<%# Eval("State") %>'
Checked='<%# Eval("stateChecked") %>'
/>
</ItemTemplate>
ASKER
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("rel atedState" ) & ", "
Next
Is there some type of findControl I can do? The checkbox value would be the state abbreviation that's in the separate 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)
Next
Is there some type of findControl I can do? The checkbox value would be the state abbreviation that's in the separate table.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I found the solution myself
foreach (DataListItem item in dlStates.Items) {
CheckBox chkStateID= (CheckBox)item.FindControl
if(chkStateID != null & chkStateID.checked)
{
}
}
based on the panel visibility you need to retrieve from different datalist.........