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

Dont hide InsertItem in 'PerformInsertCommand'

1 Answer 31 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Brindavan
Top achievements
Rank 1
Brindavan asked on 26 Feb 2009, 04:17 AM
Hi,

I am using the FormTemplate mode in EditForm settings.
When the user fills information in new item and clicks on 'Save' it fires the perfomInsert command.
I am validating data in ItemCommand method in code behind.

When the validation is successful I am rebinding the grid. Otherwise I need to display error message to user and user should still see the InsertItem. But as soon as the execution of code in 'PerformInsertCommand' completes, the new InsertItem is hidden.

How do I get around this?

Brindavan

1 Answer, 1 is accepted

Sort by
0
Accepted
Daniel
Telerik team
answered on 26 Feb 2009, 08:34 AM
Hello Brindavan,

Try the following approach:
protected void RadGrid1_InsertCommand(object source, GridCommandEventArgs e) 
    Hashtable values = new Hashtable(); 
    (e.Item as GridEditableItem).ExtractValues(values); 
    SqlDataSource1.InsertParameters.Clear(); 
    SqlDataSource1.InsertCommand = "INSERT INTO [Categories] ([CategoryName], [Description]) VALUES ('" + values["CategoryName"].ToString() + "', '" + values["Description"].ToString() + "')"
    SqlDataSource1.Insert(); 
    e.Canceled = true//this will help us keep the form opened 

Best regards,
Daniel
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Grid
Asked by
Brindavan
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Share this question
or