Click here to Skip to main content
15,885,810 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.

Here's my code, which i am using for above functionality. What change can i made to resolve my problem.
VB.NET
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
Posted
Updated 23-Mar-11 7:11am
v3

1 solution

store the newly added rows also in session and repopulate to the table
 
Share this answer
 
Comments
Rohit.Net100 23-Mar-11 13:36pm    
how to refresh session item after postback.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900