I need to add a default value to one of the textboxes when adding a new item in the grid
<telerik:GridTemplateColumn HeaderText="Activity ID" SortExpression="activityID" UniqueName="activityID" >
<ItemTemplate>
<%# Eval("activityID")%>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox runat="server" ID="txtActivity" Text='<%# Bind("activityID") %>' />
<asp:RequiredFieldValidator runat="server" ID="rfvActivity" ControlToValidate="txtActivity" Display="Dynamic" ErrorMessage="*" />
</EditItemTemplate>
</telerik:GridTemplateColumn>
When clicking “Add new recored” I need to pre-populate the txtActivity textbox. How can I access this from the code behind?
I tried this with no success
protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)
{
if (e.CommandName == RadGrid.InitInsertCommandName)
{
GridEditableItem editedItem = e.Item as GridEditableItem;
TextBox t = (TextBox)(editedItem.FindControl("txtActivity"));
}
}
And this:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
if (e.Item is GridCommandItem && e.Item.OwnerTableView.IsItemInserted)
{
TextBox txtActivity = (TextBox)e.Item.FindControl("txtActivity");
txtActivity.Text = "300";
}
}
I am running out of ideas.
Please help. Thanks