This is a migrated thread and some comments may be shown as answers.

[Solved] Preset some values on EditCommand

1 Answer 88 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
aung maw
Top achievements
Rank 1
aung maw asked on 27 Apr 2009, 12:49 AM
Hi All, In the documentation it was possible to preset some values when Insert Command fires as shown below.  How can I preset when a user clicks Edit??  Basically I'm trying to set some values before it gets into edit mode.

Please assist.
Regards,
J.




private
void RadGrid1_ItemCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
{
  
if (e.CommandName == RadGrid.InitInsertCommandName)
  {
     e.Canceled = true;
     e.Item.OwnerTableView.InsertItem();

     GridEditableItem insertedItem = e.Item.OwnerTableView.GetInsertItem();
     TextBox box = insertedItem.FindControl(
"txtEmployeeID") as TextBox;
     box.Text =
"11";
  }
}

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 27 Apr 2009, 04:12 AM
Hello,

I hope you are using a FormTemplate as your EditForm. If so you can bind your textbox declaratively to the required field using the syntax shown below so that it shows up in EditMode:
aspx:
 <EditFormSettings EditFormType="Template" > 
                <FormTemplate> 
                    <asp:TextBox ID="TextBox1" Text=<%#Bind("FirstName") %> runat="server"></asp:TextBox>                 
                </FormTemplate> 
                 
 </EditFormSettings> 

 (OR)
 you can preset the EditForm control values in the ItemDataBound event as shown below:
c#:
 protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
    { 
        if (e.Item is GridEditableItem && e.Item.IsInEditMode) 
        { 
            GridEditableItem editItem = (GridEditableItem)e.Item; 
            TextBox txtbx = (TextBox)editItem.FindControl("TextBox1"); 
            txtbx.Text = "11"
        }        
    } 

Thanks
Princy.
Tags
General Discussions
Asked by
aung maw
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or