Solved

add new row in gridview using session

Posted on 2011-03-23
6
819 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 250 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 7

Assisted Solution

by:foobarr
foobarr earned 250 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

910 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now