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:
------------
<html>
<head>
<link rel="stylesheet" type="text/css" href="datewthtime/jquery.datetimepicker.css"/>
</head>
<body>
<form id="form1" runat="server">
<asp:Repeater ID="Rep" runat ="server" >

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



</HeaderTemplate>

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

</td>
<td>
<asp:TextBox ID="Cus_name" runat="Server" Text='<%#Eval("Cus_name")%>'></asp:TextBox>
</td>
<tr>
<td>
<asp:TextBox ID="datetimepicker" runat="server"></asp:TextBox>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
<br />

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

<script src="datewthtime/jquery.js" type="text/javascript"></script>
<script src="datewthtime/jquery.datetimepicker.js" type="text/javascript"></script>
<script type="text/javascript">
$('#datetimepicker').datetimepicker({
dayOfWeekStart: 1
});

</script>

</html>


My C# Code:
----------


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

protected void Page_Load(object sender, EventArgs e)
{
BindGrid();
}



private void BindGrid()
{


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

}


protected void Button1_Click(object sender, EventArgs e)
{
string query = "";
conn.Open();
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);
cmd.ExecuteNonQuery();
}
}


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?




Responses

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

Up
0
Down
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">
$('.datetimepickercss').datetimepicker({
dayOfWeekStart: 1
});

</script>


Thanks,
A2H
My Blog

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

Login to post response