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

Rad grid Edit mode-Update issue for text Box

1 Answer 18 Views
Grid
This is a migrated thread and some comments may be shown as answers.
akpaga akpaga
Top achievements
Rank 1
akpaga akpaga asked on 16 Jul 2014, 09:57 PM
Hi friends,In the  radgrid i have a Tempalte coloumn  Which has an EditTempalte as shown below.I want to the update new value for the field User_login: User.identity.name

<telerik:GridTemplateColumn SortExpression="User_Login" UniqueName="User_Login" HeaderText="User_Login" >
<ItemTemplate>
<asp:Label Text='<%# Eval("User_Login") %>' runat="server" ID="lblUserLoginItem" />
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID ="txtUserLoginEdit" runat="server" Text='<%# Bind("User_Login") %>'> </asp:TextBox>
</EditItemTemplate>
</telerik:GridTemplateColumn>

But when I try to do the following in the code behind:  It retrieves the only the old value beacause of the bind and if i dont use the bind it does not update at all.Is there something I am missing..Please guide..thank You

protected void rgTransferDetails_ItemDataBound(object sender, GridItemEventArgs e)
{
if (e.Item is GridEditFormInsertItem && e.Item.OwnerTableView.IsItemInserted)
{
GridEditFormInsertItem item = (GridEditFormInsertItem)e.Item;
TextBox lblUserLogin = (TextBox)item.FindControl("txtUserLoginEdit");
lblUserLogin.Text = User.Identity.Name;

}

if (e.Item is GridEditFormItem && e.Item.IsInEditMode)
{
GridEditFormItem editItem = (GridEditFormItem)e.Item;
TextBox lblUserLoginEdit = (TextBox)editItem.FindControl("txtUserLoginEdit");
lblUserLoginEdit.Text = User.Identity.Name;

}

}

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 1
answered on 17 Jul 2014, 03:47 AM
Hi,

I guess you want the default value in a TextBox fields to be set to User.identity.name in edit and insert mode, please try the following code snippet:

C#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{  
 if (e.Item is GridEditableItem && e.Item.IsInEditMode)
 {
  GridEditableItem editItem = (GridEditableItem)e.Item;
  TextBox lblUserLoginEdit = (TextBox)editItem.FindControl("txtUserLoginEdit");
  lblUserLoginEdit.Text = User.Identity.Name;
 }
}

Thanks,
Princy
Tags
Grid
Asked by
akpaga akpaga
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 1
Share this question
or