Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

add new row in gridview using session

Posted on 2011-03-23
6
Medium Priority
?
834 Views
Last Modified: 2012-06-27
I have a grid, which is already populated from database.
i am inserting a new row in grid from a popup window using session variable.
now, problem is when i insert second time a new row in grid, first one disappears.
how can i solve this problem.
0
Comment
Question by:rohitnet100
  • 4
6 Comments
 
LVL 13

Accepted Solution

by:
Rick earned 1000 total points
ID: 35199901
You need to insert the new row to your datasource (datatable,dataset, ...) not to the gridview.
After inserting the new row, re-bind the gridview to its datasource.
0
 

Author Comment

by:rohitnet100
ID: 35199967
Her's my code, which i am using fro above functionality.
What change can i made to resolve my problem.

 Dim con1 As New SqlConnection(ConfigurationManager.ConnectionStrings("MyConnectionString").ConnectionString)
        con1.Open()
        Dim ada1 As New SqlDataAdapter("P_FN_PR_PopGrid", con1)
        Dim ds1 As New DataSet
        Try
            ada1.SelectCommand.CommandType = CommandType.StoredProcedure
            ada1.SelectCommand.Parameters.Add(New SqlParameter("@date", SqlDbType.DateTime)).Direction = ParameterDirection.Input
            ada1.SelectCommand.Parameters("@date").Value = Trim(RadDatePick.SelectedDate.Value)
            ada1.SelectCommand.Parameters.Add(New SqlParameter("@sc", SqlDbType.Char)).Direction = ParameterDirection.Input
            ada1.SelectCommand.Parameters("@sc").Value = Trim(ddlSc.SelectedValue)
            ada1.SelectCommand.Parameters.Add(New SqlParameter("@me", SqlDbType.Char)).Direction = ParameterDirection.Input
            ada1.SelectCommand.Parameters("@me").Value = Trim(ddlme.SelectedValue)
            ada1.Fill(ds1, "P_FN_PR_PopGrid")
            ada1.Dispose()

            If (Not IsNothing(Session("NewRec"))) Then
                Dim lst As List(Of Rec) = TryCast(Session("NewRec"), List(Of Rec))
                For Each rec As Rec In lst
                    Dim rw As DataRow = ds1.Tables(0).NewRow()
                    rw("port_rec_num") = rec.port_rec_num
                    rw("DESC_ALT") = rec.DESC_ALT
                    rw("port_no_se") = rec.port_no_se
                    rw("STD_NUM_OF_SE") = rec.STD_NUM_OF_SE
                    ds1.Tables(0).Rows.InsertAt(rw, 0)
                    Next
            End If
            GD_Prod.DataSource = ds1.Tables(0).DefaultView
            GD_Prod.DataBind()
        Catch Err As Exception
            Response.Write(Err.Message.ToString)
        Finally
            con1.Close()
        End Try
        Session.Remove("NewRec")
    End Sub
0
 

Author Comment

by:rohitnet100
ID: 35200722
how to refresh session item after postback.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 7

Assisted Solution

by:foobarr
foobarr earned 1000 total points
ID: 35218778
What if you stored your new rows as an object list and then just store the object list in session.  This way whenever you re-load the grid you can just populate it from your object list.

0
 

Author Comment

by:rohitnet100
ID: 35219017
any sample code?
0
 

Author Closing Comment

by:rohitnet100
ID: 35226685
thanks
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

926 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question