Why My datetime picker was not showing in dates on repeater control in c#?

Posted by Raghuldrag under ASP.NET on 8/20/2014 | Points: 10 | Views : 3181 | Status : [Member] | Replies : 1
Hi Friends,

i wanna create an application staff in time out time calculation,
so i show the staff_id,staff_name in repeater which has already stored in database,ve to insert only datetime with in the repeater so i made code for repeater.

in asp.net:
<link rel="stylesheet" type="text/css" href="datewthtime/jquery.datetimepicker.css"/>
<form id="form1" runat="server">
<asp:Repeater ID="Rep" runat ="server" >

<table cellpadding="1" cellspacing="1" width="100%" style="font-family:Verdana;border:1px solid #C0C0C0;background-color:#D8D8D8">
<tr bgcolor="#FF781E" >


<tr style="background-color:White">
<asp:TextBox ID="cust_Id" runat="Server" Text='<%#Eval("cust_Id")%>'></asp:TextBox>

<asp:TextBox ID="Cus_name" runat="Server" Text='<%#Eval("Cus_name")%>'></asp:TextBox>
<asp:TextBox ID="datetimepicker" runat="server"></asp:TextBox>
<br />

<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Insert" />

<script src="datewthtime/jquery.js" type="text/javascript"></script>
<script src="datewthtime/jquery.datetimepicker.js" type="text/javascript"></script>
<script type="text/javascript">
dayOfWeekStart: 1



My C# Code:

SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["AccessConnectionString"].ConnectionString);

protected void Page_Load(object sender, EventArgs e)

private void BindGrid()

SqlDataAdapter sqlAdp = new SqlDataAdapter("Select dateF from datet ", conn);
DataTable dt = new DataTable();
Rep.DataSource = dt;


protected void Button1_Click(object sender, EventArgs e)
string query = "";
foreach (RepeaterItem item in Rep.Items)
TextBox cust_id = (TextBox)item.FindControl("cust_id");
TextBox Cus_name = (TextBox)item.FindControl("Cus_name");
TextBox datetimepicker = (TextBox)item.FindControl("dateF");

query = "insert into datet values(cust_id='" + @cust_id + "',Cus_name='" + @Cus_name + "',dateF='" + datetimepicker.Text + "')";

SqlCommand cmd = new SqlCommand(query, conn);

here my problem is when i use the datetime picker outside of the repeater control its showing calender and time , inside the repeater it was not working?????
how to solve?


Posted by: A2H on: 10/5/2014 [Member] [MVP] Silver | Points: 25

The problem here is you are not referring the textbox control properly. Reason behind this is when you add the control inside Repeater the textbox ID value will change at runtime. You can find this when you select the ViewSource option in browser window.

As a solution you can try one of the below options
Using Jquery Class Selector
Add a class to your textbox like given below
 <asp:TextBox ID="datetimepicker" class="datetimepickercss" runat="server"></asp:TextBox>

and then change your jquery function like given below

    <script type="text/javascript">
dayOfWeekStart: 1


My Blog

Raghuldrag, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response