ASP.NET - setting default values for ListView InsertItemTemplate
For the DetailsView I use the following code:
protected void DetailsView1_PreRender(object sender, EventArgs e)
{
DetailsView myDetailsView = (DetailsView)sender;
//set value to current datetime
((TextBox)myDetailsView.FindControl("TextBox1")).Text =
DateTime.Now.ToString("M/d/yyyy HH:mm");
}
When I try to do the same for a ListView control (specifically the InsertItemTemplate), I get a "NullReferenceException" error.
How to set default value to Listview InsertItemTemplate textbox?
+2
source to share
1 answer
You can try using ListView's InsertItem property :
((TextBox)myDetailsView.InsertItem.FindControl("TextBox1")).Text =
DateTime.Now.ToString("M/d/yyyy HH:mm");
+4
source to share