Solved

add new row in gridview using session

Posted on 2011-03-23
6
818 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
Comment Utility
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
Comment Utility
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
Comment Utility
how to refresh session item after postback.
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 7

Assisted Solution

by:foobarr
foobarr earned 250 total points
Comment Utility
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
Comment Utility
any sample code?
0
 

Author Closing Comment

by:rohitnet100
Comment Utility
thanks
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

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 …
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.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

763 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

6 Experts available now in Live!

Get 1:1 Help Now