如何在不使用VB的ASP.NET中使用数据库连接的情况下编辑,更新和删除网格视图 [英] How to edit, update, and delete a grid view without using database connections in ASP.NET using VB

查看:63
本文介绍了如何在不使用VB的ASP.NET中使用数据库连接的情况下编辑,更新和删除网格视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的网格视图模型代码是:



 <   asp:GridView     ID   =  GridView1    OnRowEditing   =  GridView1_RowEditing    OnUpdateCommand   =  GridView1_RowUpdating    OnRowDeleting   =  GridView1_RowDeleting    runat   = 服务器    CssClass   =  fixedColWidth    CellPadding   =  0    ForeColor   = #333333   高度  =  273px >  
< AlternatingRowStyle BackColor = 白色 ForeColor = #284775 / >
< span class =code-keyword><
>
< asp:CommandField ShowEditButton = True / >
< /列 >
< <跨度class =code-leadattribute> EditRowStyle BackColor = #999999 / >
< FooterStyle BackColor = #5D7B9D 字体粗体 = True ForeColor = 白色 / >
< HeaderStyle BackColor = # 5D7B9D 字体粗体 = True ForeColor = 白色 / >
< PagerStyle BackColor = #284775 ForeColor = 白色 Horizo​​ntalAlign = 中心 / >
< RowStyle BackColor = #F7F6F3 ForeColor = #333333 / >
< SelectedRowStyle BackColor = #E2DED6 字体粗体 = True ForeColor = #333333 / >
< SortedAscendingCellStyle BackColor = #E9E7E2 / >
< SortedAscendingHeaderStyle BackColor = #506C8C / >
< SortedDescendingCellStyle BackColor = #FFFDF8 < span class =code-attribute> / >
< SortedDescendingHeaderStyle BackColor = #6F8DAE / >
< / asp:GridView >





我的VB代码:







< pre lang =vb> 公共 WebForm1
继承 System.Web.UI.Page





受保护的 Sub Page_Load( ByVal sender As 对象 ByVal e 作为系统。 Ë ventArgs)句柄 。加载
' 在页面加载上加载Excel文件
loadExcel()
结束 < span class =code-keyword> Sub

公共 功能 loadExcel()
' loadExcel将文件显示到gridView。
Dim MyConnection As System.Data.OleDb.OleDbConnection
Dim DtSet As System.Data.DataSet
Dim MyCommand As System.Data.OleDb.OleDbD ataAdapter
Dim filePath = Path.Combine(GlobalVariable.savedPath,GlobalVariable.excelFileName)
' Dim filePath =C:\ excelfiles\Book11.xlsx
' 使用Oledb连接从Excel文件获取数据的代码
MyConnection = 系统.Data.OleDb.OleDbConnection( Provider = Microsoft.ACE.OLEDB.12.0; Data Source = &安培; filePath& ;扩展属性='Excel 12.0 Xml; HDR = YES;';
' 读取从Excel电子表格中选择的工作表的代码'
MyCommand = System.Data.OleDb.OleDbDataAdapter( select * from [Sheet1 $],MyConnection)
' - 不需要额外代码将表格映射为电子表格中的列
' MyCommand.TableMappings.Add(Table,Net- informations.com)
DtSet = System.Data.DataSet
MyCommand.Fill(DtSet)
< span class =code-comment>' 使用excel电子表格填充GridView
GridView1.DataSource = DtSet.Tables( 0
' 代码下面需要显示excel到GridView
GridView1.DataBind()
MyConnection.Close( )

返回 没什么
结束 功能

结束 Class



基本上我想编辑,更新和删除网格视图而不使用任何处理使用VB在asp.net中建立数据库连接。但是,我想使用此代码来完成它。 gridview将由一个包含x列的excel表填充,我不知道有多少列。但我想单击编辑或删除并更新该列中的所有行。



我尝试了什么:



i尝试使用堆栈溢出和谷歌搜索我的问题,但没有找到帮助。有人可以帮我编码吗?

解决方案

,MyConnection)
' - 不需要额外代码,将表格映射为电子表格中的列
' < span class =code-comment> MyCommand.TableMappings.Add(Table,Net-informations.com)
DtSet = System.Data.DataSet
MyCommand.Fill(DtSet)
' 使用excel电子表格
GridView1.DataSource = DtSet.Tables( 0
' 代码下面需要显示excel到GridView
GridView1.DataBind()
MyConnection.Close()

返回
结束 功能

结束



基本上我想编辑,更新和删除网格视图而不使用任何东西来处理asp中的数据库连接.net使用VB。但是,我想使用此代码来完成它。 gridview将由一个包含x列的excel表填充,我不知道有多少列。但我想单击编辑或删除并更新该列中的所有行。



我尝试了什么:



i尝试使用堆栈溢出和谷歌搜索我的问题,但没有找到帮助。有人可以帮我编码吗?


你可以在互联网上找到很多文章。一个是 - 插入更新编辑删除记录在GridView中使用ASP.Net中的SqlDataSource [ ^ ]。


My mockup code for grid view is:

<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:



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?

解决方案

", 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?


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


这篇关于如何在不使用VB的ASP.NET中使用数据库连接的情况下编辑,更新和删除网格视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆