| id | Room Categories | single | Double | |
|---|---|---|---|---|
| <%#Container.DataItem("packageid")%> | <%#Container.DataItem("single_rate")%> |
<%#Container.DataItem("double_rate")%> |
and code behind is
Private Sub Repeater1_ItemCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles Repeater1.ItemCreated
Dim ri As RepeaterItem = CType(e.Item, RepeaterItem)
Dim elemType As ListItemType = e.Item.ItemType
If (elemType = ListItemType.Item) OrElse (elemType = ListItemType.AlternatingItem) Then
Dim cb As CheckBox = ri.FindControl("chk_packages")
AddHandler cb.CheckedChanged, AddressOf Me.myCheckedChanged
'cb.CheckedChanged += New EventHandler(CheckedChanged)
End If
End Sub
Private Sub myCheckedChanged(ByVal sender As Object, ByVal e As EventArgs)
Dim cb As CheckBox = CType(sender, CheckBox)
Dim i As Int32
Dim cbid As CheckBox
For i = 0 To Me.Repeater1.Items.Count - 1
cbid = CType(Repeater1.Items(i).FindControl("single"), CheckBox)
If Not (cbid Is Nothing) Then
If cb.Checked = True Then
cbid.Enabled = True
Else
cbid.Enabled = False
cbid.Checked = False
End If
End If
Next
End Sub
now the problem there are certain categories binded from database in repater like Deluxe PlatinumSuperior Deluxe Room or Deluxe PlatinumPremier Deluxe Room and 2 more ,also two more columns bind single and double room the data in these columns are just rate .also i show checkboxes with these two cloumns
the problem if i select category one say for example Deluxe PlatinumPremier Deluxe Room only that checkboxes get enables (means single and double not all checkboxes )
hope i m quite clears ,please keep posting ur response ,if not clear yet !!
erum mirzaPosted Dec 3, 2010, 7:07 AM
'get how many packages hav been selected
Dim c As Int32
Dim str As String
For Each dataItem As RepeaterItem In Repeater1.Items
Dim ckchecked As CheckBox = DirectCast(dataItem.FindControl("chk_packages"), CheckBox)
If ckchecked.Checked Then
Dim chk_single As CheckBox = DirectCast(dataItem.FindControl("single_rate"), CheckBox)
Dim chk_double As CheckBox = DirectCast(dataItem.FindControl("double_rate"), CheckBox)
If chk_single.Checked Then
c = c + 1
ElseIf chk_double.Checked Then
c = c + 1
End If
End If
Next
If c = 0 Then
lbl_error_package.Visible = True
lbl_error_package.Text = "please select at least one package"
Else
lbl_error_package.Visible = False
End If
now the problem i need to select at least one package with either single or double rooms
it can find control chk_packages in code behind but when it comes to line it gives exception "object reference not
set to isnatnce of an object "
<asp:Repeater ID="Repeater1" runat="server">
<HeaderTemplate>
<table border="1" width="100%">
<tr>
<th>idth>
<th align=left>Room Categoriesth>
<th>singleth>
<th>Doubleth>
tr>
HeaderTemplate>
<ItemTemplate>
<tr>
<td width="5%">
<asp:Label ID="Label3" runat="server" Text= '<%# Container.DataItem("packageid")%>' />td>
<td> <asp:CheckBox ID="chk_packages" AutoPostBack=true runat="server" Text = <%#Container.DataItem("package_name")%> /> td>
<td><%#Container.DataItem("single_rate")%><asp:CheckBox AutoPostBack=true ID="single" Enabled=false runat="server" />Number of Rooms<asp:TextBox ID="txt_single" Enabled=false width="10px" MaxLength="2" runat="server">asp:TextBox>td>
<td><%#Container.DataItem("double_rate")%><asp:CheckBox AutoPostBack=true ID="Double" Enabled=false runat="server" />Number of Rooms<asp:TextBox ID="txt_double" Enabled =false width="10px" MaxLength="2" runat="server">asp:TextBox>td>
<td>td>
tr>
ItemTemplate>
<FooterTemplate>
table>
FooterTemplate>
asp:Repeater>
CrishPosted Dec 3, 2010, 4:12 AM
Its a little complicate question but i have some code for enable check box when another check box clicked in repeater.just check this below code i think it will help you.
Example:
Private Sub myCheckedChanged(ByVal sender As Object, ByVal e As EventArgs)
Dim cb As CheckBox = CType(sender, CheckBox)
Dim i As Int32
Dim cbid As CheckBox
For i = 0 To Me.Repeater1.Items.Count - 1
cbid = CType(Repeater1.Items(i).FindControl("single"), CheckBox)
If Not (cbid Is Nothing) Then
If cb.Checked = True Then
cbid.Enabled = True
Else
cbid.Enabled = False
cbid.Checked = False
End If
End If
Next
End Sub