GridView problem under not ispostback

i have a grid and its working fine in grid i have Edit and Delete button, its working fine if i put the gridview code in GridView_Load event, if i put my code under
 If Not IsPostBack Then
 End If

then i press the Edit button then page postback and get blank since i am putting the data in session and binding grid again with session variable

Please suggest

Thanks
 
farjack1Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

HainKurtSr. System AnalystCommented:
we need code... actually you dont need to put data in session, it should be already in viewstate, no need to bind again...
0
joeyluCommented:
yes we need code, however,  

If Not IsPostBack Then
End If

means if the page is not trigger the postback, and if you put this statement in page_load, after you click the EDIT button, since the EDIT button will trigger the postback, therefore every code inside of this IF statement will not run
0
farjack1Author Commented:
markup
<asp:GridView ID="testGridView" runat="server" AutoGenerateColumns="False"
            EnableViewState="False">
            <Columns>
                <asp:BoundField DataField="gvOrderID" HeaderText="OrderID" ReadOnly="True"/>
                <asp:TemplateField HeaderText="ProductName">
                    <ItemTemplate>
                        <asp:Label id="labelProductName" runat="server" text='<%# Bind("gvProductName") %>'>></asp:Label>
                    </ItemTemplate>
                    <EditItemTemplate>
                        <asp:DropDownList id="ddlProductName" runat="server"
                             DataTextField="ProductName" DataValueField="ID" DataSource="<%# loadProducts %>" />                            
                       
                    </EditItemTemplate>                    
                </asp:TemplateField>                
                <asp:BoundField DataField="gvUnitPrice" HeaderText="UnitPrice" ReadOnly="True" SortExpression="UnitPrice" />
                <asp:BoundField DataField="gvQuantity" HeaderText="Quantity" ReadOnly="true" SortExpression="Quantity" />    
                <asp:TemplateField HeaderText="Action">
                    <ItemTemplate>
                        <asp:Button id="btnEdit" runat="server" Text="Edit" CommandName="Edit" />
                        <asp:Button id="btnDelete" runat="server" Text="Deate" CommandName="Delete" />
                    </ItemTemplate>
                    <EditItemTemplate>
                        <asp:Button id="btnUpdate" runat="server" Text="Update" CommandName="Update"/>
                        <asp:Button id="btnCancel" runat="server" Text="Cancel" CommandName="Cancel" CausesValidation="false" />
                    </EditItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>


    Protected Sub form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles form1.Load

        If Not IsPostBack Then
            loadProducts()
            loadOrderGridData
        End If

    End Sub
Private Sub loadOrderGridData()

        Dim NewRow As DataRow
        Dim table As DataTable = New DataTable("OrderDetail")
       
        Dim colItemOrderID As DataColumn = New DataColumn("gvOrderID", Type.GetType("System.String"))
        Dim colItemProductID As DataColumn = New DataColumn("gvProductID", Type.GetType("System.String"))
        Dim colItemProductName As DataColumn = New DataColumn("gvProductName", Type.GetType("System.String"))
        Dim colItemUnitPrice As DataColumn = New DataColumn("gvUnitPrice", Type.GetType("System.String"))
        Dim colItemQty As DataColumn = New DataColumn("gvQuantity", Type.GetType("System.String"))

        table.Columns.Add(colItemOrderID)
        table.Columns.Add(colItemProductID)
        table.Columns.Add(colItemProductName)
        table.Columns.Add(colItemUnitPrice)
        table.Columns.Add(colItemQty)

        ordDetailList = objOrderMapper.getOrder()

        For i = 0 To ordDetailList.Count - 1

            NewRow = table.NewRow()

            NewRow("gvOrderID") = CType(ordDetailList.Item(i), Order).OrderID  'testGridView.Rows(i).Cells(0).Text
            'gvLabelProduct = DirectCast(DirectCast(sender, GridView).Rows(i).FindControl("ddlProductName"), Label)
            NewRow("gvProductName") = CType(ordDetailList.Item(i), Order).ProductName 'gvLabelProduct.Text
            NewRow("gvUnitPrice") = CType(ordDetailList.Item(i), Order).Quantity  'testGridView.Rows(i).Cells(2).Text
            NewRow("gvQuantity") = CType(ordDetailList.Item(i), Order).UnitPrice  'testGridView.Rows(i).Cells(3).Text

            table.Rows.Add(NewRow)

        Next

        'Dim dvData As DataView = New DataView(table)
        Session("OrderTable") = table
       
        BindData()


    End Sub


    Private Sub BindData()
        Me.testGridView.DataSource = Session("OrderTable")
        Me.testGridView.DataBind()
    End Sub

 Function loadProducts() As IList
        prdList = objOrderMapper.getProducts()
        Return prdList
    End Function
0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

HainKurtSr. System AnalystCommented:
what is this doing? loadProducts is a function and used like a sub...

   Function loadProducts() As IList
        prdList = objOrderMapper.getProducts()
        Return prdList
    End Function

    Protected Sub form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles form1.Load
        If Not IsPostBack Then
            loadProducts() >>>>>>>>>>> ????? <<<<<<<<<<<
        End If
    End Sub
0
HainKurtSr. System AnalystCommented:
;) got it, you can remove this line

and also why it is form1_Load, should not it be Page_Load?
    Protected Sub form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles form1.Load
        If Not IsPostBack Then
            loadOrderGridData()
        End If
    End Sub

Open in new window

0
HainKurtSr. System AnalystCommented:
maybe you turned off your viewstate... thats why you get nothing...

do you have anything like this

EnableViewState="false"

in page/form or web config?
0
HainKurtSr. System AnalystCommented:
try this instead...
Protected Sub form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles form1.Load
  If Not IsPostBack Then Session("OrderTable") = nothing  'set it to null and refresh when on first load
  loadOrderGridData() 
End Sub

Private Sub loadOrderGridData()
  if Session("OrderTable") is nothing then
    ...
    Session("OrderTable") = table
  end if
  BindData()
End Sub

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.