After binding my session variables at set to 0

kimmie8000
kimmie8000 used Ask the Experts™
on
Once the code is binds to the grid.  I lose my session variables which makes updating an issue.

Can someone tell me how to keep my session variable for the update part of the LINQ query?

public void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
    {
        LabelAcknMessage.Text = string.Empty;
        GridView1.EditIndex = e.NewEditIndex;
        // Get table and row for editing with index selected... This is when you click edit.
        string strJobTitleName = (GridView1.Rows[e.NewEditIndex].FindControl("lblJobTitle") as Label).Text;
        if (strJobTitleName != null)
        {
            HCGASF_MaintDataContext db = new HCGASF_MaintDataContext();
            var JobTitle = (from jt in db.JobTitles
                                where jt.JobTitleName == strJobTitleName
                            select jt).SingleOrDefault();
            Session["OLD_JobTitleID"] = JobTitle.JobTitleID;
            // test string make sure it is in the right number.
            string strTitle = Session["OLD_JobTitleID"].ToString();
            intTitle = Convert.ToInt32(strTitle);
        }

        string strHCApplicationName = (GridView1.Rows[e.NewEditIndex].FindControl("lblHCApplication") as Label).Text;
        if (strHCApplicationName != null)
        {
            HCGASF_MaintDataContext db = new HCGASF_MaintDataContext();
            var HCApp = (from ap in db.HomeCareSoftwareLists
                         where ap.HCApplication == strHCApplicationName
                            select ap).SingleOrDefault();
            Session["OLD_HCApplicationID"] = HCApp.HCSoftwareID;
            // test string make sure it is in the right number.
           string strHC = Session["OLD_HCApplicationID"].ToString();
           intHC = Convert.ToInt32(strHC);
        }



        BindData();
    }
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Actually, the real problem is the following:

Value of member '' of an object of type '' changed.
A member defining the identity of the object cannot be changed.
Consider adding a new object with new identity and deleting the existing one instead.

This means I have two primary keys in a table; I need the ablity to change them.  HOW?

var matched = (from c in dc.JobTitleSpecificApps
                       where c.JobTitleID == intOldJobID && c.HCSoftwareID == IntOldHCID
                       select c).SingleOrDefault();

        //matched.JobTitleID = Convert.ToInt32(JobTitleNumb);
        matched.JobTitleID = JobTitleNumb;  Thinks it cannot change/update because it is a key.
        //matched.HCSoftwareID = Convert.ToInt32(HCApplicationNumb);
        matched.HCSoftwareID = HCApplicationNumb;  Thinks it cannot change/update because it is a key.
        matched.LikePerson = JTLikePerson.ToString();
        matched.Active = Convert.ToBoolean(UpdateActive);
        matched.CreationDate = DateTime.Now;
Aaron JabamaniTechnical Architect

Commented:
UR title says session values are lost after u bind data. Is this still there ? if so can we also see binddata method code ?

Or you a new problem ?

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial