Click here to Skip to main content
15,908,581 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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);

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.
Posted
Updated 21-Dec-10 18:18pm
v2
Comments
JF2015 22-Dec-10 0:18am    
Added code formatting.
Sandeep Mewara 22-Dec-10 1:51am    
Datepicker to texbox? Or just value of it?

Unable to get what is your issue. Getting any errors while doing so?
tulasiram3975 22-Dec-10 1:58am    
assign datepicker to each textbox not value
like $("#txtdate").datepicker();
tulasiram3975 22-Dec-10 2:01am    
if i click on first text box i get datepicker if i click second text box i need to get datepicker and so on.. because each text box contains different dates i hope you understand please help me sir..

1 solution

Assuming that you are using JQuery datepicker
http://jqueryui.com/demos/datepicker/[^]
for your question:
C#
.
.
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 + "' ).datepicker();"
      tc.Controls.Add(txtdate);    
      tr.Cells.Add(tc);  
    }  
    examtime.Controls.Add(tr);
}
if (script != string.Empty)
{
    script = "<script>$(function(){" + script + "});</script>";
    Page.ClientScript.RegisterStartupScript(this.GetType(), "registerDatePicker", script);
}
 
Share this answer
 
Comments
tulasiram3975 23-Dec-10 0:36am    
Thank You Very Much Sir
Great Answer For Me Thank You.
kapilonkar 14-Jan-13 5:38am    
I have added the above mentioned code in my function but still DatePicker is not visible.
I have User control in which I am creating Date Picker Dynamically.
Please Help Me.
Thanks
kapilonkar 14-Jan-13 6:03am    
I have added the above mentioned code in my function but still DatePicker is not visible.
I have User control in which I am creating Date Picker Dynamically.
Please Help Me.
Thanks
kapilonkar 15-Jan-13 2:34am    
Thanks Below mentioned line Helped for me as my TextBox's JScript client Id was different therefore date picker wasn't working.

Code :
wc.ClientIDMode = System.Web.UI.ClientIDMode.Static;
script += "$( '#" + wc.ClientID + "' ).datepicker();";
//Here wc is my web control which I am casting in TextBox at run time.

Thanks :)

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