Reputation: 333
Hi I have a form That accepts all employee details with submit and reset buttons. When the user clicks on the submit data will be displayed in the telerik grid below the form.
Coming to the telerik grid I only have empid and empname , edit, delete buttons.
When the user clicks on the edit button the requirement is to load the form with original data they've entered and want to edit it in the form and when they clicks the submit button they want the update operation to be done.
When I added radgrid_edicommand when ever I click On edit it is listing 2 text boxes (that I have in the grid) with employee Id and Emp name. How can I load the data in the top screen??
Upvotes: 1
Views: 1622
Reputation: 11154
Please check below code snippet.
.aspx
<div>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button4" runat="server" Text="SAVE" OnClick="Button4_Click" />
<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="false" OnNeedDataSource="RadGrid1_NeedDataSource"
OnItemCommand="RadGrid1_ItemCommand">
<MasterTableView DataKeyNames="ID">
<Columns>
<telerik:GridBoundColumn HeaderText="Name" DataField="Name" UniqueName="Name">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn HeaderText="ID" DataField="ID" UniqueName="ID">
</telerik:GridBoundColumn>
<telerik:GridEditCommandColumn>
</telerik:GridEditCommandColumn>
</Columns>
</MasterTableView>
<ClientSettings>
</ClientSettings>
</telerik:RadGrid>
</div>
.aspx.cs
protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
dynamic data = new[] {
new { ID = 1, Name ="Name1"},
new { ID = 2, Name = "Name2"},
new { ID = 3, Name = "Name3"}
};
RadGrid1.DataSource = data;
}
protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
{
if (e.CommandName == RadGrid.EditCommandName)
{
GridDataItem item = e.Item as GridDataItem;
// using DataKey get ID
Label1.Text = item.GetDataKeyValue("ID").ToString();
// using Column Get name
TextBox1.Text = item["Name"].Text;
e.Canceled = true;
}
}
protected void Button4_Click(object sender, EventArgs e)
{
//your logic
}
if this is not your case then check below link. http://demos.telerik.com/aspnet-ajax/grid/examples/dataediting/templateformupdate/defaultcs.aspx
Let me know if any concern.
Upvotes: 1