Results 1 to 7 of 7

Thread: enbable disable cehckboxes on checkbox in repeater

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2007
    Location
    Karachi
    Posts
    551

    enbable disable cehckboxes on checkbox in repeater

    see the .aspx page
    Code:
    <asp:PlaceHolder   ID="PlaceHolder3" runat="server"  Visible=false > <Strong>Hotel Requirement</Strong>
               
          
                 <asp:Repeater ID="Repeater1"  runat="server">
                 <HeaderTemplate>
    <table border="1" width="100%">
    <tr>
    <th>id</th>
    <th align=left>Room Categories</th>
    <th>single</th>
    <th>Double</th>
    
    </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" /></td>
    
    <td><%#Container.DataItem("double_rate")%><asp:CheckBox  AutoPostBack=true ID="Double" runat="server" /></td>
    <td><asp:Label ID="Label2" runat="server" Text="Label"></asp:Label></td>
    </tr>
    </ItemTemplate>
    
    <FooterTemplate>
    </table>
    </FooterTemplate>
    
                 </asp:Repeater>
             
              
    		
    		 
            </asp:PlaceHolder>
    i want when any packages checbox click in repeater two other checkbox in repeater (single,double get enable) in the same row ,whne i un-unchecked it it also disables them , iw rite some stuff in my application in order to do but its does not working as required

    now see the code
    Code:
    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
    Code:
      Private Sub myCheckedChanged(ByVal sender As Object, ByVal e As EventArgs)
    
    /// i need help here 
    
    end sub

    any urgent help is requested
    There is no achievement without goals

  2. #2
    PowerPoster motil's Avatar
    Join Date
    Apr 2009
    Location
    Tel Aviv, Israel
    Posts
    2,143

    Re: enbable disable cehckboxes on checkbox in repeater

    did you tried to set the AutoPostBack of property of the checkbox to true?
    * Rate It If you Like it

    __________________________________________________________________________________________

    "Programming is like sex: one mistake and you’re providing support for a lifetime."

    Get last SQL insert ID

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2007
    Location
    Karachi
    Posts
    551

    Re: enbable disable cehckboxes on checkbox in repeater

    that problem ahs been resolved in this way
    Code:
    Private Sub myCheckedChanged(ByVal sender As Object, ByVal e As EventArgs)
    
            Dim chkPkg As CheckBox = DirectCast(sender, CheckBox)
            Dim ri As RepeaterItem = DirectCast(chkPkg.NamingContainer, RepeaterItem)
    
            If chkPkg.Checked = True Then
                DirectCast(ri.FindControl("single"), CheckBox).Enabled = chkPkg.Checked
                DirectCast(ri.FindControl("Double"), CheckBox).Enabled = chkPkg.Checked
    
            Else
                DirectCast(ri.FindControl("single"), CheckBox).Checked = chkPkg.Checked
                DirectCast(ri.FindControl("Double"), CheckBox).Checked = chkPkg.Checked
    
    
                DirectCast(ri.FindControl("single"), CheckBox).Enabled = chkPkg.Checked
                DirectCast(ri.FindControl("Double"), CheckBox).Enabled = chkPkg.Checked
    
                DirectCast(ri.FindControl("txt_single"), TextBox).Enabled = chkPkg.Checked
                DirectCast(ri.FindControl("txt_double"), TextBox).Enabled = chkPkg.Checked
    
    
            End If
    
    
            'Dim cb As CheckBox = CType(sender, CheckBox)
            'Dim rp As RepeaterItem = CType(cb.NamingContainer, RepeaterItem)
            ''Dim lb As Label = CType(Repeater1.Items(3).FindControl("Label2"), Label)
            'Dim lb As Label
            ''        lb.Text = "You selected row " & rp.ItemIndex.ToString()
    
    
            '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)
            '    lb = CType(Repeater1.Items(i).FindControl("Label2"), Label)
    
    
            '    'lb.Text = "You selected row " & rp.ItemIndex.ToString()
            '    'lb.Text = "You selected row " & rep
    
            '    If Not (cbid Is Nothing) And cb.Checked = True Then
            '        If cb.Checked = True Then
            '            cbid.Enabled = True
            '            Exit For
            '        Else
            '            cbid.Enabled = False
            '            cbid.Checked = False
    
    
            '        End If
            '    End If
    
            'Next
        End Sub
    
        Private Sub singleCheckedChanged(ByVal sender As Object, ByVal e As EventArgs)
            Dim chksingl As CheckBox = DirectCast(sender, CheckBox)
            Dim ri As RepeaterItem = DirectCast(chksingl.NamingContainer, RepeaterItem)
    
            If chksingl.Checked = True Then
                DirectCast(ri.FindControl("txt_single"), TextBox).Enabled = chksingl.Checked
            Else
                DirectCast(ri.FindControl("txt_single"), TextBox).Enabled = chksingl.Checked
    
    
            End If
            'DirectCast(ri.FindControl("txt_double"), TextBox).Enabled = chkPkg.Checked
    
    
        End Sub
        Private Sub doubleCheckedChanged(ByVal sender As Object, ByVal e As EventArgs)
            Dim chkdouble As CheckBox = DirectCast(sender, CheckBox)
            Dim ri As RepeaterItem = DirectCast(chkdouble.NamingContainer, RepeaterItem)
    
            If chkdouble.Checked = True Then
                DirectCast(ri.FindControl("txt_double"), TextBox).Enabled = chkdouble.Checked
            Else
                DirectCast(ri.FindControl("txt_double"), TextBox).Enabled = chkdouble.Checked
    
            End If
            'DirectCast(ri.FindControl("txt_double"), TextBox).Enabled = chkPkg.Checked
    
    
        End Sub
    see the code
    Code:
        '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
    I need to check at least one package must be selected with either single/double room packages .in above codes nippt it says "NOTHING" when i put break point on this line
    Code:
     Dim chk_single As CheckBox = DirectCast(dataItem.FindControl("single_rate"), CheckBox)
    please reply me if need further desscription
    There is no achievement without goals

  4. #4
    ASP.NET Moderator gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: enbable disable cehckboxes on checkbox in repeater

    Hello,

    Has your ASPX markup changed from what you posted above? I don't see any control called "single_rate" in the ASPX markup for the ItemTemplate.

    Gary

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2007
    Location
    Karachi
    Posts
    551

    Re: enbable disable cehckboxes on checkbox in repeater

    yes gep i corrected day 2 days ago already ...and forgot to post on vbforums sorry for that .

    but there is another kind of problem that most probably i will post next time, any way thanks for pointing ou the problem
    There is no achievement without goals

  6. #6
    ASP.NET Moderator gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: enbable disable cehckboxes on checkbox in repeater

    Hey,

    Not a problem at all.

    If this particular question has been resolved, you might want to think about posting your final solution so that others can learn, and then mark your thread as resolved.

    Thanks

    Gary

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2007
    Location
    Karachi
    Posts
    551

    Re: enbable disable cehckboxes on checkbox in repeater

    let me post my updated code
    Code:
    <div>
    										<asp:UpdatePanel ID="UpdatePanel4" runat="server" UpdateMode=conditional>
    
    <ContentTemplate>
     	
    										
    											<table class="right_txt_space_accm" width="100%" border="0" cellspacing="0" cellpadding="0">
    											  <tr>
    												<td width="50%" align="left"><strong>Do you want Hotel Booking  </strong></td>
    													
    												<td width="50%" align="left"><strong></strong>   
                                                        <asp:RadioButtonList EnableViewState=true  RepeatDirection=Horizontal  ID="Rdbtn_hotelbook"  
                                                            runat="server" AutoPostBack="True">
                                                            <asp:ListItem Value="0">Yes</asp:ListItem>
                                                            <asp:ListItem Selected="True" Value="1">No</asp:ListItem>
                                                        </asp:RadioButtonList>
                                                       
                                                      </td>
    											  </tr>
    											</table>
    													
    											<div runat=server visible=false id="hotel_div" style="border:dotted 1px black;"> 
    																					
    		<asp:PlaceHolder   ID="PlaceHolder3" runat="server"  Visible=false > <Strong>Hotel Requirement</Strong>
               
          
                 <asp:Repeater ID="Repeater1"  runat="server">
                 <HeaderTemplate>
    <table border="1" width="100%">
    <tr>
    <th>id</th>
    <th align=left>Room Categories</th>
    <th>single</th>
    <th>Double</th>
    
    </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><asp:FilteredTextBoxExtender
            ID="FilteredTextBoxExtender1" FilterMode=ValidChars ValidChars="0123456789"  TargetControlID=txt_single  runat="server">
        </asp:FilteredTextBoxExtender>
    </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><asp:FilteredTextBoxExtender
            ID="FilteredTextBoxExtender2" FilterMode=ValidChars ValidChars="0123456789"  TargetControlID=txt_double  runat="server">
        </asp:FilteredTextBoxExtender></td>
    <td></td>
    </tr>
    
    
              
    
    </ItemTemplate>
    
    <FooterTemplate>
       
    </table>
               
    </FooterTemplate>
    
             </asp:Repeater>
             <div id=date_check visible=true runat=server>
              <strong>Check-In Date</strong> <asp:TextBox  ID="txt_checkin"  runat="server" onchange="checkdate(this);"></asp:TextBox>
    <a  href="javascript:calendar_window=window.open('calendar.aspx?form1=form1.txt_checkin','calendar_window','width=554,height=488');calendar_window.focus()">
    <img alt=""  src="images/calendar.png"    />  
            </a> 
                  
      <strong>Check-Out Date</strong> <asp:TextBox  ID="txt_checkout"  runat="server" onchange="checkdate(this);"></asp:TextBox>
    <a href="javascript:calendar_window=window.open('calendar.aspx?form1=form1.txt_checkout','calendar_window','width=554,height=488');calendar_window.focus()">
    <img  alt=""  src="images/calendar.png"   />  
            </a>  
         
             </div>
             
            <br />   
        <asp:Label ID="lbl_error_package"  ForeColor="Red" Visible=false  runat="server" Text="Label"></asp:Label>
    <br />
    <br />
    <asp:RequiredFieldValidator ID="RequiredFieldValidator9" ControlToValidate=txt_checkout runat="server" ErrorMessage="please enter check out Date"></asp:RequiredFieldValidator>      
                <br />
    		    <asp:RequiredFieldValidator ID="RequiredFieldValidator10" ControlToValidate=txt_checkin runat="server" ErrorMessage="please enter check in Date"></asp:RequiredFieldValidator>      
                <asp:CompareValidator  ControlToValidate=txt_checkout ControlToCompare=txt_checkin ID="CompareValidator1" Operator=GreaterThan runat="server"  ErrorMessage="Check out date should be greater than check in date"></asp:CompareValidator>
             
    		 
            </asp:PlaceHolder> 
          
                                                </div> 
                                                
                                                </ContentTemplate>
                                                <Triggers>
                                                <asp:AsyncPostBackTrigger ControlID="Rdbtn_hotelbook" EventName="SelectedIndexChanged" />
                                                                   
    
                    </Triggers>
                                                
                                    </asp:UpdatePanel>
    										</div>
    										<div>
     <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode=conditional>
    
    <ContentTemplate>
                                                <table  class="right_txt_space_accm" width="100%" border="0" cellspacing="0" cellpadding="0">
                                                  <tr>
                                                    <td width="40%" align="left"><strong>Do you want to take booth</strong></td>
                                                    <td width="60%" align="left"><strong>
                                                   <asp:RadioButtonList EnableViewState=true  ID="rdbtn_booth"   CellSpacing=13 OnSelectedIndexChanged=rdbtn_booth_SelectedIndexChanged RepeatDirection=Horizontal  runat="server"  AutoPostBack="true">
                                                            <asp:ListItem>1</asp:ListItem>
                                                            <asp:ListItem>2</asp:ListItem>
                                                            <asp:ListItem>3</asp:ListItem>
                                                            <asp:ListItem>4</asp:ListItem>
                                                            <asp:ListItem>5</asp:ListItem>
                                                           
                                                        </asp:RadioButtonList>   </strong></td>
                                                  </tr>
                                                </table>
                                          
         <asp:PlaceHolder  ID="PlaceHolder5" runat="server"></asp:PlaceHolder>
                                            
                                                </ContentTemplate>
                                                <Triggers>
                                               <asp:AsyncPostBackTrigger ControlID="rdbtn_booth" EventName="SelectedIndexChanged" />
                                               </Triggers>
                                               
                                    </asp:UpdatePanel>
                                            </div>
    i u have a single on my code u find that checkin date and checkout date should be outside of teh repeater , i want that if no pckage is selected i.e no checkbox from chk_packages checkin and checkout date shoube disable or at least hide .

    please keep posting me if need further clarification of problem
    There is no achievement without goals

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width