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

Add / Edit records using code behind

4 Answers 115 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Debashis Pyne
Top achievements
Rank 1
Debashis Pyne asked on 30 Jun 2010, 09:33 AM
Hi,

I am a new user to the Telerik controls.
My requirements are to display, add, edit, activate and deactivate records from the Radgrid.

Now the above functionalities are required to be integrated using code behind, c# pages.
The stored procedures, middle layer c# classes have been written already.

I need to integrate the controls by creating objects of the classes and then bind the controls usign the methods in the classes.
I found the edit and add functionalities have been integrated using the ASPX codes, which is not my requirement.

Code examples would be of great help.

Thanks.

Regards,
Debashis

4 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 30 Jun 2010, 11:21 AM
Hello,


I hope the following code libraries will be of help in achieving the required.
Update/Insert/Delete with stored procedures and SqlDataSource control
Manual Insert/Update/Delete using FormTemplate and Sql backend


-Shinu.
0
Debashis Pyne
Top achievements
Rank 1
answered on 30 Jun 2010, 11:31 AM
Hi Shinu,

Thanks for your reply.
This will help me with my requirements.

Regards,
Debashis
0
Debashis Pyne
Top achievements
Rank 1
answered on 30 Jun 2010, 12:07 PM
Hi Shinu,

I tried to integrate the edit fucntionality using the examples you provided.
I encountered with the "ArgumentOutOfRangeException" in the following code:

protected

 

void grdActionList_UpdateCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)

 

{

Label1.Text =

"wow";

 

 

GridEditableItem editedItem = e.Item as GridEditableItem;

 

 

//Get the primary key value using the DataKeyValue.

 

 

//string ActionId = editedItem.OwnerTableView.DataKeyValues[editedItem.ItemIndex]["Action_Id"].ToString();

 

 

 

//string CustomerID = editedItem.OwnerTableView.DataKeyValues[editedItem.ItemIndex]["CustomerID"].ToString();

 

 

 

//Access the textbox from the edit form template and store the values in string variables.

 

 

'Error'     string JOMCID = (editedItem["JOMC_Id"].Controls[0] as TextBox).Text;

 

 

Label1.Text = JOMCID;

 

}

I have also attached the screenshot of the error.
Can you please suggest?

Thanks,
Debashis

0
Debashis Pyne
Top achievements
Rank 1
answered on 30 Jun 2010, 12:36 PM
Hi Shinu,

The above issue have been resolved.

However I have another issue.
The issue is:

When I try to update the record with new data from the textbox, the control doesnot take the new value, but keeps the old value.
The following is the code:

*********************************************************************************************************************************************************

 

//Label1.Text = "wow";

 

 

GridEditableItem editedItem = e.Item as GridEditableItem;

 

 

//Get the primary key value using the DataKeyValue.

 

 

string ActionId = editedItem.OwnerTableView.DataKeyValues[editedItem.ItemIndex]["Action_Id"].ToString();

 

 

//Access the textbox from the edit form template and store the values in string variables.

 

 

string JOMCID = (editedItem["JOMC_ID"].Controls[0] as TextBox).Text;

 

 

//Label1.Text = JOMCID;

 

 

//try

 

 

//{

 

JOMCMiddleWare.BL.

Actions oAct = new JOMCMiddleWare.BL.Actions();

 

oAct._JOMC_ID = JOMCID;

oAct._Action_Id = System.

Convert.ToInt32(ActionId);

 

oAct._Content_Id = 8;

oAct._Content_Text =

"c4";

 

oAct._Updated_By = System.

Convert.ToInt32(Session[JOMCSession.__Session_User_Id]);

 

oAct._Module_Id = System.

Convert.ToInt32(Session[JOMCSession.__Session_Lanuage_Id]);

 

oAct._Company_Id = System.

Convert.ToInt32(Session[JOMCSession.__Session_Company_Id]);

 

 

int iResult = oAct.editAction();

 

Label1.Text = iResult.ToString();

*********************************************************************************************************************************************************

In the above code, the variable JOMCID takes the old value rather the new value from the edit popup form.

Please suggest.

Thanks,
Debashis

Tags
Grid
Asked by
Debashis Pyne
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Debashis Pyne
Top achievements
Rank 1
Share this question
or