Solved

add new row in gridview using session

Posted on 2011-03-23
6
828 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

621 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