将datepicker分配给运行时文本框 [英] assign datepicker to runtime textboxes
本文介绍了将datepicker分配给运行时文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
这是我的代码.
我创建了动态表,例如:
Hi all,
here is my code.
I have created dynamic table like:
//dynamic table
Table examtime = new Table();
//examtime.ID = "examtime";
TableHeaderCell thc = new TableHeaderCell();
TableHeaderRow hr = new TableHeaderRow();
Label dat = new Label();
dat.Text = "Date";
thc.Controls.Add(dat);
hr.Cells.Add(thc);
examtime.Controls.Add(hr);
for (int b = 0; b< Convert.ToInt32(TextBox1.Text); b++)
{
TableRow tr = new TableRow();
for (int i = 0; i < 1; i++)
{
TableCell tc = new TableCell();
//here is the date column i need to apply datepicker to each textbox
TextBox txtdate = new TextBox();
txtdate.ID = "dpicker" +b.ToString();
txtdate.Width = 75;
tc.Controls.Add(txtdate);
tr.Cells.Add(tc);
}
examtime.Controls.Add(tr);
}
PlaceHolder1.Controls.Add(examtime);
根据textbox1的值,它创建了动态文本框,因此我需要为每个文本框分配datepicker.这是我的问题.谁能帮我吗?
预先感谢.
According to the textbox1 value it creates dynamic textboxes so I need to assign datepicker to every textbox. This is my problem. Can anyone please help me?
Thanks in advance.
推荐答案
假设您正在使用JQuery datepicker
http://jqueryui.com/demos/datepicker/ [
Assuming that you are using JQuery datepicker
http://jqueryui.com/demos/datepicker/[^]
for your question:
.
.
examtime.Controls.Add(hr);
string script = string.Empty;
for (int b = 0; b < Convert.ToInt32(TextBox1.Text); b++)
{
TableRow tr = new TableRow();
for (int i = 0; i < 1; i++)
{
TableCell tc = new TableCell();
TextBox txtdate = new TextBox();
txtdate.ID = "dpicker" +b.ToString();
txtdate.Width = 75;
script += "
('#" + txtdate. ID + " tc.Controls.Add(txtdate); tr.Cells.Add(tc); } Examtime.Controls.Add(tr); } 如果(脚本!= 字符串 .Empty) { 脚本= "
( '#" + txtdate.ID + "' ).datepicker();" tc.Controls.Add(txtdate); tr.Cells.Add(tc); } examtime.Controls.Add(tr); } if (script != string.Empty) { script = "<script>
(function(){" +脚本+ " ; Page.ClientScript.RegisterStartupScript(此 .GetType()," registerDatePicker",脚本); }
(function(){" + script + "});</script>"; Page.ClientScript.RegisterStartupScript(this.GetType(), "registerDatePicker", script); }
这篇关于将datepicker分配给运行时文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文