2
Answers

How to insert date time picker with in repeater control?

Rocky Rocky

Rocky Rocky

10y
2.3k
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 database table:
------------------------
 create table datet
(
Cust_id int identity,
cus_name varchar(200),
dateF datetime
)
insert into datet (cus_name) values ('ram')
insert into datet (cus_name) values ('sam') 
 
 
 

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 cust_Id,Cus_name,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?
Answers (2)