Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

add new row in gridview using session

Posted on 2011-03-23
6
Medium Priority
?
832 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 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
Industry Leaders: 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!

 
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

718 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