• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 56
  • Last Modified:

Update gridview before sending data to Excel

Hi Experts,

on the screen In a grid view all the parts are displayed. I have a button. When I click it I have to generate a purchase order and send it to Excel.  These are the steps I am doing.

1. select the parts on the gridview you want to send.
2.create a data table to move all the selected parts.
3.Generate a purchase order number.
4.Update the gridview  with purchase order number if it is selected for the purchase order.
5.Send the contents of the created data table to excel.

Before I send data to Excel I need to update the gridview. I am able to send data to excel. But unable to update the gridview before I send data.

I hope I explained the properly. Please help!!

This is my code.

 Protected Sub cmdGeneratePO_Click(sender As Object, e As EventArgs) Handles cmdGeneratePO.Click
        Try
            Dim JobNo As String = ddlJob.SelectedItem.Value
            Dim PONumber As String = Generate_PO_Number()
            Dim dt As New DataTable()
            dt = Make_DataTableFor_PO_RFQ()
            If dt.Rows.Count = 0 Then
                MessageBox("Please select the parts", lblMessage)
                Exit Sub
            End If

            Dim totBOMCost As Double
            lblTotalCost.Text = ""
            If dt.Rows.Count > 0 Then
                For Each row As DataRow In dt.Rows
                    Dim cost As Double = row("TotalCost")
                    totBOMCost = totBOMCost + cost
                Next
            End If

            Dim Cust_Name As String = ddlCustomer.SelectedItem.Text
            Dim Bom_Name As String = ddlBOM.SelectedItem.Text
            ''Update the PO number in the DB
            Update_PONum_BOM(dt, PONumber)
            'Fill the grid
            Dim Sql As String = " SELECT Parts.partID, Parts.ManufacturerPartNo as ManuPartNo,                            Parts.LastOrderedCost,Parts.PartDescription as Description, " & _
                            " MANUFACTURER.ManuName as Manufacturer, bom.BomMstID, bom.QtyOrdered, bom.QtyReceived, bom.QtyRequired as Quantity,Parts.LastOrderedCost*bom.QtyRequired as Cost, bom.ExpectedDelDt, " & _
                            " bom.WearSparePartFlag,BOM.PONum  FROM BOM, PARTS, Manufacturer where parts.PartID = bom.PartID and parts.ManuID = Manufacturer.ManuID and " & _
                            " BOM.CustomerID=" & ddlCustomer.SelectedItem.Value & " and JobNum = '" & ddlJob.SelectedItem.Value & "' and BomID = " & ddlBOM.SelectedItem.Value & " and RevisionLvl='" & ddlRevLvl.SelectedItem.Value & "' order by ManuPartNo"
            Dim rowCount As Integer = Fill_SelectedParts_Grid(Sql)
           Export_PO_ToExcel(dt, Cust_Name, Bom_Name, JobNo, totBOMCost, PONumber)


        Catch ex As Exception
            MessageBox("Error while generating PO :" & ex.Message, lblMessage)
        End Try
       
    End Sub


 "Fill_SelectedParts_Grid" should update the grid. Infact it is updating if I remove "Export_PO_ToExcel(dt, Cust_Name, Bom_Name, JobNo, totBOMCost, PONumber)" code.
0
RadhaKrishnaKiJaya
Asked:
RadhaKrishnaKiJaya
  • 2
1 Solution
 
JHMH IT StaffCommented:
Why not just draw a new gridview with the updated info based on the datatable you created when selecting the parts?
0
 
RadhaKrishnaKiJayaAuthor Commented:
Thank you for your reply. Actually I do not need another gridview. Because the problem is,  the gridview do not update if there is a Excel code after that. But I found a way to do it. I have created a hidden button and call its click event from client side after updating the gridview.

My code is:-
create a hidden button :
<asp:Button ID="cmdExport" runat="server" ClientIDMode="Static" style="display:none;" OnClick="cmdExport_Click" /><!--Hidden button  -->

<script type="text/javascript">
        function ExportExcel() { //function to be executed from server side after gridview is bound
            $('#cmdExport').click();
        }
    </script>

Protected Sub cmdExport_Click(sender As Object, e As EventArgs) Handles cmdExport.Click
        'cmdExport is a hidden button used just to send the data to Excel file. This click event is called from the    client side code

             Export_PO_ToExcel(dtPOExcel, Cust_Name, Bom_Name, JobNo, totBOMCost, gPONumber)
    End Sub
0
 
RadhaKrishnaKiJayaAuthor Commented:
Thank you everyone for your help.  The resolution I have already described.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now