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

Rad Grid Two Sources - One to Select, One to Insert/Update/Delete

2 Answers 36 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mariella
Top achievements
Rank 1
Mariella asked on 03 Nov 2011, 02:29 PM
Hello,

I am very new to Telerik. So I apologize if this is a silly question... but, I have been looking at the forum and I am unable to find the right solution for my problem. I need to display a list of documents in a grid that is coming from DataSource1(DS1). Once the user selects a row in edit mode (He may choose to change an original field or not...), I need to insert or update the row in another DataSource2(DS2). I was able to successfully display the list from DS1 and bring the edit mode. In the code behind, I wrote an updateCommand method where I would take the editable values and send them to my store procedure in DS2. The issue I am facing is. I am not able to retrieve the field I modify on my form. It is retirving the original one displayed from DS1. How do I retrieve the value I modified on the screen and send it to my code behind? Bellow a snnipets of my code.

<

 

 

telerik:RadGrid ID="RadGrid1" GridLines="None" runat="server" AllowAutomaticDeletes="True" AllowAutomaticInserts="True" PageSize="10"

 

 

 

AllowAutomaticUpdates="True" AllowPaging="True" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" OnUpdateCommand="RadGrid1_UpdateCommand"

 

 

 

OnDataBound="RadGrid1_DataBound">

 


....

<

 

 

asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:GCOM %>"

 

 

 

ProviderName="System.Data.OracleClient" SelectCommand="Select * from GA_DOC D, GA_DOC_Evidence E, GA_Evidence Ev

 

where D.DOC_ID = E.DOC_ID (+)

and E.EVIDENCE_ID = Ev.EVIDENCE_ID (+)

and LIVE_DATE is not null

and ARCHIVE_DATE is null

and DOC_TYPE_ID = 3"

 

 

OldValuesParameterFormatString="original_{0}" ConflictDetection="CompareAllValues">

 


....

protected

 

 

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

 

{

 

 

GridEditableItem item = (GridEditableItem)e.Item;

 

 

 

String documentId = item.GetDataKeyValue("DOC_ID").ToString();

 

 

 

String title = item.GetDataKeyValue("TITLE").ToString();

 

 

 

String price = item.GetDataKeyValue("SALE_PRICE").ToString();

 

 

 

SqlConnection conn = null;

 

 

 

SqlDataReader rdr = null;

 

conn =

 

new SqlConnection(ConfigurationManager.ConnectionStrings["FTPFactoryConnStr"].ConnectionString);

 

 

 

try

 

{

 

 

//Open the connection and save data on Application's SQL DB.

 

conn.Open();

 

 

SqlCommand cmd = new SqlCommand(ConfigurationManager.AppSettings["ADDCONTROLFILE"].ToString(), conn);

 

cmd.CommandType =

 

CommandType.StoredProcedure;

 

cmd.Parameters.Add(

 

new SqlParameter("@FTPAction", "N"));

 

cmd.Parameters.Add(

 

new SqlParameter("@ExpirationDate", new DateTime(DateTime.Now.Ticks + 2).ToString("yyyyMMdd")));

 

cmd.Parameters.Add(

 

new SqlParameter("@ResearchId", Convert.ToInt32(documentId)));

 

cmd.Parameters.Add(

 

new SqlParameter("@Ticker", "abc"));

 

cmd.Parameters.Add(

 

new SqlParameter("@PPVDocumentPrice", price));

 





Thank you!
Mariella.  

2 Answers, 1 is accepted

Sort by
0
Andrey
Telerik team
answered on 07 Nov 2011, 10:49 AM
Hello Mariella,

DataKeyValue is modified after successful update to the database. So it is expected to get the old results. However, you could access the new values by using the following code:

GridEditableItem item = (GridEditableItem)e.Item;
String documentId = (item["DOC_ID"].Controls[0] as TextBox).Text;
String title = (item["TITLE"].Controls[0] as TextBox).Text;
String price = (item["SALE_PRICE"].Controls[0] as TextBox).Text;

Thus you will get the new values from the form.

Regards,
Andrey
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
0
Mariella
Top achievements
Rank 1
answered on 07 Nov 2011, 03:16 PM
Hello Andrey,

thanks for your reply. Yes, I ended up doing what you suggested.


Thank you again!
Mariella.
Tags
Grid
Asked by
Mariella
Top achievements
Rank 1
Answers by
Andrey
Telerik team
Mariella
Top achievements
Rank 1
Share this question
or