Page view counter

Cant get Linq to databind newest info

Last post 02-08-2008 5:57 PM by fubaroptik. 0 replies.

Sort Posts:

  • Cant get Linq to databind newest info

    02-08-2008, 5:57 PM
    • Loading...
    • fubaroptik
    • Joined on 04-20-2007, 5:56 PM
    • Posts 15

    When I edit a row in a gridview and click update, the linq object in the gridview has a stored procedure that changes the data that was updated, but even if I try to re-databind the gridview or its linqdatasource, it doesnt show the new info.

    Here's a simplified version of the tables:
    CREATE TABLE [dbo].[Surveys](
        [ID] [int] IDENTITY(1,1) NOT NULL
    PRIMARY KEY CLUSTERED ([ID] ASC))

    CREATE TABLE [dbo].[Questions](
        [ID] [int] IDENTITY(1,1) NOT NULL
    PRIMARY KEY CLUSTERED ([ID] ASC))

     CREATE TABLE [dbo].[SurveyQuestions](
        [SurveyID] [int] NOT NULL,
        [QuestionID] [int] NOT NULL,
        [Ordinal] [tinyint] NOT NULL,
    PRIMARY KEY CLUSTERED
    ([SurveyID] ASC, [QuestionID] ASC))

     

    On the webform there's two gridviews. The first gridview just displays all the surveys and has a Select button on each row.  The second gridview shows all the surveyquestions that belong to the survey selected in the first gridview.

    In the linq sturcture, the update command for the surveyquestions object is a stored procedure, the only thing special that the procedure does is re-order all the Ordinal values for the surveyquestion.  So if on the selected survey, I have surveyquestions with ordinals of 0,1,2,3,4,5 and I do an update on the surveyquestion with an ordial of 2 and try to change it to an ordinal of 8, the stored procedure correctly reorders them so that 0 and 1 stay the same, 3, 4, & 5 become 2, 3, & 4, and the one I changed (2) becomes 5, even though I tried to change it to 8.

    So when I edit the row for ordinal 2, and select 8, and click update, the stored procedure does work correctly and updates the table in the database correctly.  However the gridview doesnt update the values to match those in the table. 

    Problem 1: 

    So what I did was I tried on both the SurveyQuestionsGridView's RowUpdated() event and also on the SurveyQuestionsLinqDataSource's Updated() event I added code to re - databind() BOTH the SurveyQuestionsLinqDataSource and the SurveyQuestionsGridView in that order.  But even though on both events I called another databind, the gridview still shows the value 8 for the ordinal even though there is no 8 in the sql table.

    Problem 2: 

    Here's the other thing, I figured if I disabled the viewstate it would force it to get the new data..  setting the EnableViewState to false on the SurveyQuestionsLinqDataSource has no effect.

    And if I set the EnableViewState to false on the SurveyQuestionsGridView, then I get a DuplicateKeyException when I click the update button on the gridview.
     

    If anyone can help fix one or both of these it would be awesome.

    Thanks! 

Page 1 of 1 (1 items)
Microsoft Communities