c# - ASP .NET - Setting the value of a DetailsView TextBox -
I use the code-behind (Page_load or prerender) to set a date-time text box in a description Trying to do this is default for a current date-time.
The effort I have made (one of several forms):
Protected Zero Details View2_PreRender (Object Sender, EventArgs e) {((Text box) DetailsView 2.Find control ("date_time"). Text = datetime.Now.ToString ("d"); }
But whatever I get is a 'nullreferenceexation' error.
Am I doing wrong?
You can use the description details control databound event to define values within your description view :
& lt; Asp: Label ID = "Description View2" runat = "server" OnDataBound = "DetailsView2_DataBound" & gt; & Lt; / ASP: Labels & gt;
Code Back:
Protected Zero Details View2_DataBound (Object Sender, EventArgs E) {DetailsView myDetailsView = (DetailsView) Sender; If (myDetailsView.CurrentMode == DetailsViewMode.Edit) {((TextBox) myDetailsView.FindControl ("date_time")). Text = datetime.Now.ToString ("d"); }}
Comments
Post a Comment