I have been following your examples and created a RadGrid very similar to http://demos.telerik.com/aspnet-ajax/grid/examples/dataediting/usercontroleditform/defaultcs.aspx
in EditFormSettings I use PopUpSettings-Modal="true" and then <FormTemplate> I list a number of text boxes.
One of these text boxes is for a datetime field. I would like it so that when the user clicks "add new record" and the pop up shows up that in the form in this text box is prepopulated with the current date. I can't seem to get this working. This is my code:
protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
{
String strDate = DateTime.Today.ToString();
if (e.CommandName == RadGrid.InitInsertCommandName) //Runs when "Add new" button clicked
{
//Code to prepopulate field (But Doesn't Work)
GridCommandItem item = (GridCommandItem)e.Item; /*If I try with data item I get error: Unable to cast object of type 'Telerik.Web.UI.GridCommandItem' to type 'Telerik.Web.UI.GridDataItem'. */
TextBox txtname = (TextBox)item.FindControl("txtDate"); //txtDate is the name of the txtbox I want to prepopulate
txtname.Text = strDate;
}
However because its in a pop up it can't find the control and I get error: "NullReferenceException was unhandled by usercode, Object reference not set to an instance of an object."
Is this(Prepopulating a form template textbox inside a popup) even possible to do?... If so how?... Thank You
in EditFormSettings I use PopUpSettings-Modal="true" and then <FormTemplate> I list a number of text boxes.
One of these text boxes is for a datetime field. I would like it so that when the user clicks "add new record" and the pop up shows up that in the form in this text box is prepopulated with the current date. I can't seem to get this working. This is my code:
protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
{
String strDate = DateTime.Today.ToString();
if (e.CommandName == RadGrid.InitInsertCommandName) //Runs when "Add new" button clicked
{
//Code to prepopulate field (But Doesn't Work)
GridCommandItem item = (GridCommandItem)e.Item; /*If I try with data item I get error: Unable to cast object of type 'Telerik.Web.UI.GridCommandItem' to type 'Telerik.Web.UI.GridDataItem'. */
TextBox txtname = (TextBox)item.FindControl("txtDate"); //txtDate is the name of the txtbox I want to prepopulate
txtname.Text = strDate;
}
However because its in a pop up it can't find the control and I get error: "NullReferenceException was unhandled by usercode, Object reference not set to an instance of an object."
Is this(Prepopulating a form template textbox inside a popup) even possible to do?... If so how?... Thank You