Click here to Skip to main content
15,898,987 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Hi,

i am trying to use a datepicker within a nested repeater. but everytime i try to change the date in the 2nd or 3rd item of the repeater by clicking the textbox, a calendar appears as expected. But the value I select is displayed in the 1st item of the repeater.


Here is the javascript:

XML
<script type="text/javascript">
       var e = jQuery.noConflict();
       e(document).ready(function () {
           e("#<%= datepicker.ClientID %>, #datepicker").datepicker({
               changeMonth: true,
               changeYear: true
           });
       });
</script>


Here is my aspx code:

<asp:Repeater runat="server" ID="rpfollowup">
                <ItemTemplate>
               
<div class="widget-body">
			
						
                                  <!-- Group -->
                              <div class="control-group">

<table border="0" width="100%">
  <tr>
    
    <td align="right"><label class="control-label" style="width:auto; float:none;">  مخرج:</label></td>
      <td align="right" width="75%"><asp:TextBox runat="server" ID="txtOut" Text='<%#Eval("Output")%>'></asp:TextBox></td>
  
    
    </tr>
    
           <tr>
     <td align="right"><asp:TextBox runat="server" ID="ffid" Visible="false" Text='<%#Eval("id")%>'></asp:TextBox></td></tr>

 
</table>
                  <div class="row-fluid">              
                                     <asp:Repeater runat="server" ID="rpactivity" >
                <ItemTemplate>
                                  <table width="100%" border="0" cellpadding="0" cellspacing="0">

        <thead>
	<tr>
                            <th style="font-weight:bold" width="150" height="40" >الأنشطة </th>

                        <th style="font-weight:bold" width="150" height="40" >تاريخ البدء</th>
	</tr>
</thead>
        <tr>
            
              <td > <asp:TextBox  ID="Activities" runat="server" CssClass="span10"   Text='<%#Eval("Activity")%>'></asp:TextBox></td>
            <td > <asp:TextBox  ID="datepicker" runat="server" CssClass="span10" ClientIDMode="Static"  Text='<%#Eval("Start_Date")%>'></asp:TextBox></td>
 
        </tr>  
   
    </table>  </ItemTemplate></asp:Repeater>
   

						  </div></div>  
								
                                
				
				</div>

                
                 </ItemTemplate>
                </asp:Repeater>


how can i pass the value of the textbox(datepicker) within the nested repeater to the jquery and how do i have to change my jquery? Thanks in advance
Posted
Updated 25-Nov-14 20:03pm
v2

1 solution

The problem is that you're having multiple identical IDs - use class instead and change ID based on row number or some other criteria so that each row has unique calendarID. You can do this server side in OnDataBound event.

Add the class .datepicker-repeater to item template.

XML
e(document).ready(function () {
        e(".datepicker-repeater").datepicker({
            changeMonth: true,
            changeYear: true
        });




If this helps please take time to accept the solution. Thank you.
 
Share this answer
 
v2
Comments
Divya Aq 26-Nov-14 3:42am    
Hi sinisa,

Thank You for the answer.

ID can be changed in the OnDataBound event. But how use the jquery on that ID?
Could you please help me with a sample code.

Thank You
Divya Aq 26-Nov-14 3:50am    
i mean, how to pass the ID of the datepicker textbox of the repeater to jquery?
Sinisa Hajnal 26-Nov-14 7:07am    
Use "this" keyword. It should reference current object which is that particular textbox. Right?
Divya Aq 26-Nov-14 7:57am    
yes, but could you please reframe the jquery for me? i am a little weak with jquery.
Sinisa Hajnal 26-Nov-14 8:34am    
You have to change only the selector, see updated solution. So add class to the template and call datepicker on the class instead of id.

If this doesn't work, you'll have to use select event on the calendar to set the value correctly.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900