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

[Solved] Code behind update using ling

3 Answers 205 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Randy
Top achievements
Rank 1
Randy asked on 18 Apr 2008, 09:45 PM
I wired up an event to update a linq data guy. linq is simple or sorta cause I'm just learning it. Everything works really cool with auto updates, deletes, and inserts however catching an edited value and in this case I want to encrypt and decrypt the ssn.
 
I can't seem to get the blankety blank edited values out of the Rad Grid. Some code I been working on and of course all the stuff that is commented out I couldn't get to work.

Isn't there an easy way to get the value from an edited textbox. You know the stuff someone types in a textbox when they clicked on edit. Sheesh!
UserControl userControl = (UserControl)e.Item.FindControl(GridEditFormItem.EditFormUserControlID);
(userControl.FindControl("admissionID") as TextBox).Text I keep getting errors on this guy. Null Reference and Object not set to an instance etc.

protected

void Update_Command(object source, Telerik.WebControls.GridCommandEventArgs e)

{

//GridEditableItem editedItem = e.Item as GridEditableItem;

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

This is what I'd like to do is get the blankety blank row ID of the row I'm editing
//string admissionID = (userControl.FindControl("admissionID") as TextBox).Text;  I get error with object not set to....null reference etc. when code above is uncommented out for userControl


This is what I'd like to do is get the blankety blank edited stuff
//string ssn = (userControl.FindControl("ssn") as TextBox).Text; I get error with object not set to....null  reference when code above is uncommented out for userControl

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

//Hashtable newValues = new Hashtable();

//newValues["admissionID"] = (userControl.FindControl("admissionID") as TextBox).Text;

//newValues["ssn"] = (userControl.FindControl("ssn") as TextBox).Text;

//TextBox admissionIDTxBx = (TextBox)userControl.FindControl("admissionID");

//TextBox ssnIDTxBx = (TextBox)userControl.FindControl("ssn");

var db = new admissions_appsDataContext();

var query = from s in db.admission_app2s

where s.admissionID == "randysolutions@hotmail.com" would like to put admissionID grabed as edited row field identifier

select s;

foreach (var thisItem in query)

{

//foreach (DictionaryEntry entry in newValues)

//{

//if (thisItem.admissionID == admissionIDTxBx.Text)

thisItem.ssn =

"123456789"; would like to put ssn The stuff entered in the editable textbox as this code with everything commented out simply updates this row in the database. 

//}

//if (thisItem.admissionID == (userControl.FindControl("admissionID") as TextBox).Text)

//{

// thisItem.ssn = "12345";//(userControl.FindControl("ssn") as TextBox).Text;

//}

}

db.SubmitChanges();

//var db = new admissions_appsDataContext();

//db.SubmitChanges(

var dbRefresh = new admissions_appsDataContext();

var queryRefresh = db.admission_app2s;

RadGrid1.DataSource = queryRefresh;

RadGrid1.DataBind();

3 Answers, 1 is accepted

Sort by
0
Randy
Top achievements
Rank 1
answered on 19 Apr 2008, 12:04 AM
OK I was able to get admissionID

string

admissionID = e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["admissionID"].ToString();

how do I get the edited fields or a collection I tryed

GridEditFormItem

gridEditFormItem = (GridEditFormItem)e.Item;

Hashtable ht = new Hashtable();

gridEditFormItem.ExtractValues(ht);


foreach (var thisItem in query)

{

foreach (DictionaryEntry entry in ht)

{

This would work however the value is the old value not the value entered into the edit textbox.
thisItem.ssn = entry.Value.ToString();

}

0
Randy
Top achievements
Rank 1
answered on 19 Apr 2008, 01:53 AM
This is what the example code for update. The Value "123456789" is the original value. The Value I entered into the edit textbox displayed when editing was something else. I am not getting the value entered into the edit textbox. If I was this would be done and finished as it updates fine.
0
Randy
Top achievements
Rank 1
answered on 19 Apr 2008, 03:39 PM
Fixed it as I looked at the Thread: "Can't get RadGrid's ExtractValuesFromItem to work" by: bemara57

using OnPreRender solved my issue as well and now I'm getting the edited values.
You guys are smart guys.

bemara57 said:

Thanks but I found that it was a timing issue. First I did this (which made the grid go all blank when I clicked anything like the edit button):

    protected void Page_Load(object sender, EventArgs e)
    {    
        if (!Page.IsPostBack)
        {
            RadGrid1.DataSource = membershipProvider.GetAllUsers();
            RadGrid1.DataBind();
        }
    }

I had to do this to get it working:
    protected override void OnPreRender(EventArgs e)
    {
        RadGrid1.DataSource = membershipProvider.GetAllUsers();
        RadGrid1.DataBind();

        base.OnPreRender(e);
    }

Tags
Grid
Asked by
Randy
Top achievements
Rank 1
Answers by
Randy
Top achievements
Rank 1
Share this question
or