0

From a hyperlink I need default values to appear when a RadGrid PopUp opens in "Add New" mode. It works fine when a RadButton is clicked (CommandName="InitInsert"). For that I set defaults in the RadGrid_ItemCommand:

if (e.CommandName == RadGrid.InitInsertCommandName)
{
    e.Canceled = true; 
    Hashtable values = GetDefaultValues();
    e.Item.OwnerTableView.InsertItem(values); 
}

The RadGrid's MasterTableView has EditMode="PopUp". To cause the PopUp to appear from a link I've passed the text "AddNew" in the queryString. Then in PageLoad I set RadGrid.MasterTableView.IsItemInserted = true; as described here. What I can't figure out is how do I get default values to appear in the PopUp that is triggered from a hyperlink? A code sample would be much appreciated.

Community
  • 1
  • 1
DeveloperDan
  • 4,626
  • 9
  • 40
  • 65
  • Have you tried binding the controls in the EditItemTemplate? Text='<%# Bind("column") %>' – Kramb Mar 02 '16 at 20:09
  • I was planning to use code behind. The default values will be user name, date added, customer code etc. I don't know if I can do that with binding but I'll look into it. – DeveloperDan Mar 02 '16 at 20:59
  • If you want to do it in code behind, do it in the itemdatabound event and then check if the grid is in edit mode. Then set the value of the controls in the template from the code behind by reference the row you have selected. – Kramb Mar 02 '16 at 21:03
  • Sounds promising. Can you post an answer with a code sample? – DeveloperDan Mar 02 '16 at 21:45

1 Answers1

0
protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
    if(e.Item is GridEditableItem && e.Item.IsInEditMode)
    {
        if(e.Item is GridEditFormItem)
        {
            GridEditFormItem item = (GridEditFormItem)e.Item;
            TextBox TextBox1 = (TextBox)item.FindControl("TextBox1");
            TextBox1.Text = item["column"].Text;
        }
    }
}
Kramb
  • 1,082
  • 10
  • 18