Click here to Skip to main content
15,896,474 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
My mockup code for grid view is:

ASP.NET
<asp:GridView ID="GridView1" OnRowEditing="GridView1_RowEditing" OnUpdateCommand="GridView1_RowUpdating" OnRowDeleting="GridView1_RowDeleting" runat="server" CssClass="fixedColWidth" CellPadding="0" ForeColor="#333333" Height="273px">
                  <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
                    <Columns>
                        <asp:CommandField ShowEditButton="True" />
                    </Columns>
                  <EditRowStyle BackColor="#999999" />
                  <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                  <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                  <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
                  <RowStyle BackColor="#F7F6F3" ForeColor="#333333"/>
                  <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
                  <SortedAscendingCellStyle BackColor="#E9E7E2" />
                  <SortedAscendingHeaderStyle BackColor="#506C8C" />
                  <SortedDescendingCellStyle BackColor="#FFFDF8" />
                  <SortedDescendingHeaderStyle BackColor="#6F8DAE" />
                  </asp:GridView>


My VB code:



VB
Public Class WebForm1
           Inherits System.Web.UI.Page





            Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
                       'Load Excel File on Page Load
                       loadExcel()
           End Sub

       Public Function loadExcel()
               'loadExcel Function to show the file to the gridView.
               Dim MyConnection As System.Data.OleDb.OleDbConnection
               Dim DtSet As System.Data.DataSet
               Dim MyCommand As System.Data.OleDb.OleDbDataAdapter
               Dim filePath = Path.Combine(GlobalVariable.savedPath, GlobalVariable.excelFileName)
               'Dim filePath = "C:\excelfiles\Book11.xlsx"
               'Code to Use an Oledb Connection to get data from the Excel File
               MyConnection = New System.Data.OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & filePath & ";Extended Properties='Excel 12.0 Xml;HDR=YES;';")
               'Code to Read the Sheet Selected from the Excel Spread Sheet'
               MyCommand = New System.Data.OleDb.OleDbDataAdapter("select * from [Sheet1$]", MyConnection)
               '-- Extra Code Not Needed which Maps the tables as Columns from the Spreadsheet
               'MyCommand.TableMappings.Add("Table", "Net-informations.com")
               DtSet = New System.Data.DataSet
               MyCommand.Fill(DtSet)
               'Populates GridView with the excel Spreadsheet
               GridView1.DataSource = DtSet.Tables(0)
               'Code Below needed to show the excel to GridView
               GridView1.DataBind()
               MyConnection.Close()

               Return Nothing
           End Function

   End Class

Basically I want to to edit, update, and delete a grid view without using anything to deal with database connections in asp.net using VB. However, i want to do it using this code. The gridview will be populated by an excel sheet with x amount of columns which i am not sure of how many. but i want to click edit or delete and update all rows in that column.

What I have tried:

i tried using stack overflow and googling my issue but found no help. Can someone help me code this?
Posted
Updated 5-May-16 17:58pm
Comments
CHill60 3-May-16 10:58am    
Not many people use Excel on the server ... and as this is code-behind you're not going to be able to use Office on the client machine.
You're not making it very clear what you actually want to do ... click edit? Update all rows in that column how? Do you only want it on the page or are you hoping to update the spreadsheet as well?
JT1992 3-May-16 11:05am    
it should update the page and the spreadsheet. and if we cant update the spreadsheet then the page alone is fine.
JT1992 3-May-16 14:25pm    
Anything?
CHill60 3-May-16 18:40pm    
Well I'm not going to write the code for you ...
What is the exact issue? Have you handled the exceptions? Have you debugged?

1 solution

You can find many articles on internet. One is - Insert Update Edit Delete record in GridView using SqlDataSource in ASP.Net[^].
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900