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

[Solved] Grid- Insert using WebuserControl

3 Answers 133 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Sekar udayamurthy
Top achievements
Rank 1
Sekar udayamurthy asked on 01 Mar 2010, 09:32 AM
Hi
First of all a Great product. I have used this example below and built a page.
http://demos.telerik.com/aspnet-ajax/grid/examples/dataediting/usercontroleditform/defaultcs.aspx


Everything works perfectly , I see the grid, I am able to Edit/Insert rows into the grid. I have one small problem though. When I insert a new row, I am able to add the row using the webuser control but the webuser control stays on the grid, The grid does not get refreshed and the edit form does not go away, but on edit, everything works as required, the edit form shows up, I am able to make changes and when I click update the grid shows up with the updated row.

Any ideas on why the insert would not refresh the grid ?

thanks
Sekar

3 Answers, 1 is accepted

Sort by
0
Martin
Telerik team
answered on 02 Mar 2010, 07:32 AM
Hi Sekar udayamurthy,

Generally speaking, when an insert command is triggered, RadGrid fires the InsertCommand event and then rebinds itself to reflect the changes. However if you set e.Canceled = true; inside the InsertCommand handler the grid would not rebind and the insert form would stay open. To test this on the online demo, just try to enter a completely empty new item.

My suggestion is to ensure that you do not call e.Canceled = true in your InsertCommand handler, unless it is in a catch block as demonstrated in the online example.

I hope this helps,
Martin
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Sekar udayamurthy
Top achievements
Rank 1
answered on 03 Mar 2010, 03:38 AM
Thank you for your response. However I do not have a e.cancelled in my code other than on exception. I have pasted the my code below. Please do let me know what I would need to do for the grid to refresh.

 

protected void rgCustomerJob_InsertCommand(object source, GridCommandEventArgs e)

 

{

 

GridEditableItem editedItem = e.Item as GridEditableItem;

 

 

UserControl userControl = (UserControl)e.Item.FindControl(GridEditFormItem.EditFormUserControlID);

 

 

//Create new row in the DataSource

 

 

DataRow newRow = this.CustomerJob.NewRow();

 

 

//Insert new values

 

 

Hashtable newValues = new Hashtable();

 

newValues[

"ParentRef"] = (userControl.FindControl("ddlParent") as DropDownList).SelectedItem.Value;

 

newValues[

"JobName"] = (userControl.FindControl("txtJobName") as TextBox).Text;

 

newValues[

"JobType"] = (userControl.FindControl("ddlType") as DropDownList).SelectedItem.Value;

 

newValues[

"JobDescription"] = (userControl.FindControl("txtDesc") as TextBox).Text;

 

newValues[

"JobStatus"] = (userControl.FindControl("ddlStatus") as DropDownList).SelectedItem.Value;

 

newValues[

"JobStartdate"] = (userControl.FindControl("txtStart") as TextBox).Text;

 

newValues[

"JobEndDate"] = (userControl.FindControl("txtFinish") as TextBox).Text;

 

newValues[

"Percent_Complete"] = (userControl.FindControl("txtFinish") as TextBox).Text;

 

newValues[

"Custom_1"] = (userControl.FindControl("txtCustom1") as TextBox).Text;

 

newValues[

"Custom_2"] = (userControl.FindControl("txtCustom2") as TextBox).Text;

 

newValues[

"Custom_3"] = (userControl.FindControl("txtCustom3") as TextBox).Text;

 

newValues[

"Custom_4"] = (userControl.FindControl("txtCustom4") as TextBox).Text;

 

 

//make sure that unique primary key value is generated for the inserted row

 

newValues[

"CustomerJobId"] = (int)this.CustomerJob.Rows[this.CustomerJob.Rows.Count - 1]["CustomerJobId"] + 1;

 

 

try

 

{

 

foreach (DictionaryEntry entry in newValues)

 

{

newRow[(

string)entry.Key] = entry.Value;

 

}

 

this.CustomerJob.Rows.Add(newRow);

 

 

this.CustomerJob.AcceptChanges();

 

 

 

}

 

catch (Exception ex)

 

{

 

Label lblError = new Label();

 

lblError.Text =

"Unable to insert CustomerJob. Reason: " + ex.Message;

 

lblError.ForeColor = System.Drawing.

Color.Red;

 

rgCustomerJob.Controls.Add(lblError);

e.Canceled =

true;

 

}

}

0
Princy
Top achievements
Rank 2
answered on 03 Mar 2010, 09:21 AM
Hi Sekar,

The grid might stay in edit/insert mode if you perform manual updates/inserts with code and accidentally set AllowAutomaticUpdates or AllowAutomaticInserts to true. Check whether this is the reason for the mentioned behavior with your grid configuration. If so, set these properties to false, as they are required only for AutomaticOperations.

Thanks
Princy.
Tags
Grid
Asked by
Sekar udayamurthy
Top achievements
Rank 1
Answers by
Martin
Telerik team
Sekar udayamurthy
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Share this question
or