本文介绍了asp.net中的gridview更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 大家好 i创建了管理界面,以便审核用户门户网站的数据,使用asp.net作为网站服务 在此页面管理员首先选择表格从下拉列表中查看 在他选择的网格视图中显示带有详细信息视图控件的数据以插入新记录 i创建了4个sqldatasourses,限制为4个表 ,然后管理员从下拉列表中选择表名,网格视图填充其数据 我的问题是更新不起作用它不会影响数据 aspx.vb页面: Imports Microsoft.VisualBasic Imports System.Data.SqlClient Imports System.Drawing Imports System.Drawing.Imaging Imports System.Drawing.Text Imports System.Data Partial 公共 类 admin 继承 System.Web.UI。 Page Dim cls As 新 clsMainFunctions 公共 ReadOnly sqlCN1 As 新 SqlConnection(ConfigurationManager.ConnectionStrings( JPRCCS )。ConnectionString) 受保护的 Sub Page_Load( ByVal sender 作为 对象, BYVAL e As System.EventArgs)句柄 我 .Load GridView1.DataSource = SqlDataSource1 GridView1.DataBind() DetailsView1.DataSourceID = SqlDataSource1 DetailsView1.DataBind() 如果 不 IsPostBack 然后 GridView1.DataBind() DetailsView1.DataBind() 结束 如果 结束 Sub 受保护的 Sub DropDownList1_SelectedIndexChanged( ByVal sender 作为 对象, ByVal e As EventArgs)句柄 DropDownList1.SelectedIndexChanged Dim tablename As String = 选择 案例 DropDownList1.SelectedIndex 案例 0 tablename = TB_ShareHolders_RG GridView1.DataSource = SqlDataSource1 GridView1.DataBind() DetailsView1.DataSourceID = SqlDataSource1 DetailsView1.DataBind() 案例 1 tablename = SHARE_news GridView1.DataSource = SqlDataSource2 GridView1.DataBind() DetailsView1。 DataSourceID = SqlDataSource2 DetailsView1.DataBind() 案例 2 tablename = SH_events GridView1.DataSource = SqlDataSource3 GridView1.DataBind() DetailsView1.DataSourceID = SqlDataSource3 DetailsView1.DataBi nd() 案例 3 tablename = tb_Announcement GridView1.DataSource = SqlDataSource4 GridView1.DataBind() DetailsView1.DataSourceID = SqlDataSource4 DetailsView1.DataBind() 案例 4 tablename = SharePrice GridView1.DataSource = SqlDataSource5 GridView1.DataBind() DetailsView1.DataSourceID = SqlDataSource5 DetailsView1.DataBind() 结束 选择 结束 Sub 私有 Sub GridView1_PageIndexChanging ( ByVal 发件人作为 对象, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles GridView1.PageIndexChanging GridView1.PageIndex = e.NewPageIndex End Sub 私有 Sub GridView1_RowCreated( ByVal 发件人作为 对象, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs)句柄 GridView1 .RowCreated 结束 Sub 私有 Sub GridView1_RowDeleting( ByVal sender 作为 对象, ByVal e As System.Web.UI.WebControls.GridViewDeleteEventArgs)句柄 GridView1.RowDeleting GridView1。 DataBind() 结束 Sub 私有 Sub GridView1_RowEditing( ByVal sender 作为 对象, ByVal e As System.Web.UI.WebControls.GridViewEditEventArgs)句柄 GridView1.RowEditing GridView1.EditIndex = e.NewEditIndex GridView1.DataBind() 结束 Sub 私有 Sub GridView1_RowUpdated( ByVal sender 作为 对象, ByVal e As System.Web.UI.WebControls.GridViewUpdatedEventArgs)句柄 GridView1.RowUpdated GridView1.EditIndex = -1 ' 绑定网格 GridView1.DataBind() 结束 Sub 私有 Sub GridView1_RowUpdating( ByVal 发件人作为 对象, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs)句柄 GridView1.RowUpdating GridView1.EditIndex = -1 ' 绑定网格 GridView1.DataBind() 结束 Sub 受保护的 Sub GridView1_SelectedIndexChanged( ByVal 发件人作为 对象, ByVal e As EventArgs)句柄 GridView1.SelectedIndexChanged 结束 Sub 结束 Class .aspx页面: < !DOCTYPE html PUBLIC - // W3C // DTD XHTML 1.0 Transitional // EN http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd > < html xmlns = http://www.w3.org/1999/xhtml > < head runat = 服务器 > < title > < / title > < style type = text / css > .style1 {宽度:100%; } .style2 {身高:151px; } .style3 {} < / style > < / head > < 正文 > < 表格 id = form1 runat = 服务器 > < div > < table class = style1 > < tr > < td class = style2 colspan = 2 > & nbsp; < / td > < / tr > < tr > < td class = style3 > & nbsp; < / td > < td > & nbsp; < / td > < / tr > < tr > < td class = style3 > < asp:DropDownList ID = DropDownList1 runat = server AutoPostBack = True > < asp:ListItem > 用户< / asp:ListItem > < asp:ListItem > 新闻< / asp:ListItem > < asp:ListItem > 事件< / asp:ListItem > < asp:ListItem > 公告< / asp:ListItem > < asp:ListItem > 股价< / asp:ListItem > < / asp:DropDownList > < br / > < / td > < td > & nbsp; < / td > < / tr > < tr > < td class = style3 colspan = 2 > < asp:GridView ID = GridView1 runat = server AllowPaging = True CellPadding = 4 ForeColor = #333333 GridLines = 无 AllowSorting = True AutoGenerateEditButton = True AutoGenerateSelectButton = True AutoGenerateDeleteButton = True 高度 = 310px 宽度 = 1060px > < RowStyle BackColor = #E3EAEB / > < 列 > < asp:CommandField / > < / Columns > < FooterStyle BackColor = #1C5E55 字体粗体 = 真 ForeColor = 白色 / > < PagerStyle BackColor = #666666 ForeColor = 白色 HorizontalAlign = 中心 / > < SelectedRowStyle BackColor = #C5BBAF 字体粗体 = True ForeColor = #333333 / > < HeaderStyle BackColor = #1C5E55 Font-Bold = True ForeColor = 白色 / > < EditRowStyle BackColor = #7C6F57 / > < AlternatingRowStyle BackColor = White / > < / asp:GridView > < asp:DetailsView ID = DetailsView1 runat = 服务器 AutoGenerateInsertButton=\"True\" Height=\"76px\" Width=\"1064px\" BackColor=\"White\" Borde rColor=\"#E7E7FF\" BorderStyle=\"None\" BorderWidth=\"1px\" CellPadding=\"3\" GridLines=\"Horizontal\"> <FooterStyle BackColor=\"#B5C7DE\" ForeColor=\"#4A3C8C\" /> <RowStyle BackColor=\"#E7E7FF\" ForeColor=\"#4A3C8C\" /> <PagerStyle BackColor=\"#E7E7FF\" ForeColor=\"#4A3C8C\" HorizontalAlign=\"Right\" /> <HeaderStyle BackColor=\"#4A3C8C\" Font-Bold=\"True\" ForeColor=\"#F7F7F7\" /> <EditRowStyle BackColor=\"#738A9C\" Font-Bold=\"True\" ForeColor=\"#F7F7F7\" /> <AlternatingRowStyle BackColor=\"#F7F7F7\" /> </asp:DetailsView> <asp:Label ID=\"ErrorMessageLabel\" runat=\"server\"></asp:Label> <asp:SqlDataSource ID=\"SqlDataSource1\" runat=\"server\" ConnectionString=\"<%$ ConnectionStrings:JPRCnewConnectionString %>\" DeleteCommand=\"DELETE FROM [TB_ShareHolders_RG] WHERE [HolderNo] = @HolderNo\" InsertCommand=\"INSERT INTO [TB_ShareHolders _RG] ([HolderNo], [Password]) VALUES (@HolderNo, @Password)\" SelectCommand=\"SELECT [HolderNo], [Password] FROM [TB_ShareHolders_RG]\" UpdateCommand=\"UPDATE [TB_ShareHolders_RG] SET [Password] = @Password WHERE [HolderNo] = @HolderNo\"> <DeleteParameters> <asp:Parameter Name=\"HolderNo\" Type=\"String\" /> </DeleteParameters> <UpdateParameters> <asp:Parameter Name=\"Password\" Type=\"String\" /> <asp:Parameter Name=\"HolderNo\" Type=\"String\" /> </UpdateParameters> <InsertParameters> <asp:Parameter Name=\"HolderNo\" /> <asp:ControlParameter ControlID=\"TextBox2\" Name=\"Password\" PropertyName=\"Text\" Type=\"String\" /> </InsertParameters> </asp:SqlDataSource> <br /> </td> </tr> <tr> <td class=\"style3\" colspan=\"2\"> <asp:SqlDataSource ID=\"SqlDataSource2\" runat=\"server\" ConnectionString=\"<%$ ConnectionStrings:JPRCnewConnectionString %>\" DeleteCommand=\"DELETE FROM [SHARE_news] WHERE [NewsId] = @NewsId\" InsertCommand=\"INSERT INTO [SHARE_news] ([NewsId], [NewsTitle], [NewsImg], [NewsFull], [NewsStatus], [NewsEntry], [NewsEntryDateAndTime], [NewsDate]) VALUES (@NewsId, @NewsTitle, @NewsImg, @NewsFull, @NewsStatus, @NewsEntry, @NewsEntryDateAndTime, @NewsDate)\" Selec tCommand=\"SELECT * FROM [SHARE_news]\" UpdateCommand=\"UPDATE [SHARE_news] SET [NewsTitle] = @NewsTitle, [NewsImg] = @NewsImg, [NewsFull] = @NewsFull, [NewsStatus] = @NewsStatus, [NewsEntry] = @NewsEntry, [NewsEntryDateAndTime] = @NewsEntryDateAndTime, [NewsDate] = @NewsDate WHERE [NewsId] = @NewsId\"> <DeleteParameters> <asp:Parameter Name=\"NewsId\" Type=\"Int32\" /> </DeleteParameters> <UpdateParameters> <asp:Parameter Name=\"NewsTitle\" Type=\"String\" /> <asp:Parameter Name=\"NewsImg\" Type=\"String\" /> <asp:Parameter Name=\"NewsFull\" Type=\" String\" /> <asp:Parameter Name=\"NewsStatus\" Type=\"String\" /> <asp:Parameter Name=\"NewsEntry\" Type=\"String\" /> <asp:Parameter Name=\"NewsEntryDateAndTime\" Type=\"DateTime\" /> <asp:Parameter Name=\"NewsDate\" Type=\"String\" /> <asp:Parameter Name=\"NewsId\" Type=\"Int32\" /> </UpdatePa rameters> <InsertParameters> <asp:Parameter Name=\"NewsId\" Type=\"Int32\" /> <asp:Parameter Name=\"NewsTitle\" Type=\"String\" /> <asp:Parameter Name=\"NewsImg\" Type=\"String\" /> <asp:Parameter Name=\"NewsFull\" Type=\"String\" /> <asp:Parameter Name=\"NewsStatus\" Type=\"String\" /> <asp:Parameter Name=\"NewsEntry\" Type=\"String\" /> <asp:Parameter Name=\"NewsEntryDateAndTime\" Type=\"DateTime\" /> <asp:Parameter Name=\"NewsDate\" Type=\"String\" /> </InsertParameters> </asp:SqlDataSource> <br /> </td> </tr> <tr> <td class=\"style3\" colspan=\"2\"> <asp:SqlDataSource ID=\"SqlDataSource3\" runat=\"server\" ConnectionString=\"<%$ ConnectionStrings:JPRCnewConnectionString %>\" DeleteCommand=\"DELETE FROM [SH_events] WHERE [eventID] = @eventID\" InsertCommand=\"INSERT INTO [SH_events] ([eventID], [eventDate], [eventTitle], [eventdesc]) VALUES (@eventID, @eventDate, @eventTitle, @ eventdesc)\" SelectCommand=\"SELECT * FROM [SH_events]\" UpdateCommand=\"UPDATE [SH_events] SET [eventDate] = @eventDate, [eventTitle] = @eventTitle, [eventdesc] = @eventdesc WHERE [eventID] = @eventID\"> <DeleteParameters> <asp:Parameter Name=\"eventID\" Type=\"Int32\" /> </DeleteParameters> <UpdateParameters> <asp:Parameter DbType=\"Date\" Name=\"eventDate\" /> <asp:Parameter Name=\"eventTitle\" Type=\"String\" /> <asp:Parameter Name=\"eventdesc\" Type=\"String\" /> <asp:Parameter Name=\"eventID\" Type=\"Int32\" /> </UpdateParameters> <InsertParameters> <asp:Parameter Name=\"eventID\" Type=\"Int32\" /> <asp:Parameter DbType=\"Date\" Name=\"eventDate\" /> <asp:Parameter Name=\"eventTitle\" Type=\"String\" /> <asp:Parameter Name=\"eventdesc\" Type=\"String\" /> </InsertParameters> </asp:SqlDataSource> </td> </tr> <tr> <td class=\"style3\" colspan=\"2\"> <asp:SqlDataSource ID=\"SqlDataSource4\" runat=\"server\" ConnectionString=\"<%$ ConnectionStrings:JPRCnewConnectionString %>\" DeleteCommand=\"DELETE FROM [tb_Announcement] WHERE [AnnoucmentID] = @AnnoucmentID\" InsertCommand=\"INSERT INTO [tb_Announcement] ([Ann_Title], [Ann_Des], [Ann_Date], [Ann_Status], [Ann_Lang]) VALUES (@Ann_Title, @Ann_Des, @Ann_Date, @Ann_Status, @Ann_Lang)\" SelectCommand=\"SELECT * FROM [tb_Announcement]\" UpdateCommand=\"UPDATE [tb_Announcement] SET [Ann_Title] = @Ann_Title, [Ann_Des] = @Ann_Des, [Ann_Date] = @Ann_Date, [Ann_Status] = @Ann_Status, [Ann_Lang] = @Ann_Lang WHERE [AnnoucmentID] = @AnnoucmentID\"> <Delete Parameters> <asp:Parameter Name=\"AnnoucmentID\" Type=\"Int32\" /> </DeleteParameters> <UpdateParameters> < asp:Parameter Name=\"Ann_Title\" Type=\"String\" /> <asp:Parameter Name=\"Ann_Des\" Type=\"String\" /> <asp:Parameter Name=\"Ann_Date\" DbType=\"Date\" /> <asp:Parameter Name=\"Ann_Status\" Type=\"String\" /> <asp:Parameter Name=\"Ann_Lang\" Type=\"String\" /> <asp:Parameter Name=\"AnnoucmentID\" Type=\"Int32\" /> </UpdateParameters> <InsertParameters> <asp:Parameter Name=\"Ann_Title\" Type=\"String\" /> <asp:Parameter Name=\"Ann_Des\" Type=\"String\" /> <asp:Parameter DbType=\"Date\" Name=\"Ann_Date\" /> <asp:Parameter Name=\"Ann_Status\" Type=\"String\" /> <asp:Parameter Name=\"Ann_Lang\" Type=\"String\" /> </InsertParameters> </asp:SqlDataSource> </td> </tr> <tr> <td class=\"style3\" colspan=\"2\"> <asp:SqlDataSource ID=\"SqlDataSource5\" runat=\"server\" ConnectionString=\"<% $ ConnectionStrings:JPRCnewConnectionString %>\" DeleteCommand=\"DELETE FROM [SharePrice] WHERE [ID] = @ID\" InsertCommand=\"INSERT INTO [SharePrice] ([shareprice], [date]) VALUES (@shareprice, @date)\" SelectCommand=\"SELECT * FROM [SharePrice]\" UpdateCommand=\"UPDATE [SharePrice] SET [shareprice] = @shareprice, [date] = @date WHERE [ID] = @ID\"> <DeleteParameters> <asp:Parameter Name=\"ID\" Type=\"Int32\" /> </DeleteParameters> <UpdateParameters> <asp:Parameter Name=\"shareprice\" Type=\"Int32\" /> <asp:Parameter Name=\"date\" DbType=\"Date\" /> <asp:Parameter Name=\"ID\" Type=\"Int32\" /> </UpdateParameters> <InsertParameters> <asp:Parameter Name=\"shareprice\" Type=\"Int32\" /> <asp:Parameter Name=\"date\" DbType=\"Date\" /> </InsertParameters> </asp:SqlDataSource> </td> </tr> </table> </div> </form> </body> </html> 解决方案 ConnectionStrings:JPRCnewConnectionString %>\" DeleteCommand=\"DELETE FROM [TB_ShareHolders_RG] WHERE [HolderNo] = @HolderNo\" InsertCommand=\"INSERT INTO [TB_ShareHolders_RG] ([HolderNo], [Password]) VALUES (@HolderNo, @Password)\" SelectCommand=\"SELECT [HolderNo], [Password] FROM [TB_ShareHolders_RG]\" UpdateCommand=\"UPDATE [TB_ShareHolders_RG] SET [Password] = @Password WHERE [HolderNo] = @HolderNo\"> <DeleteParameters> <asp:Parameter Name=\"HolderNo\" Type=\"String\" /> </DeleteParameters> < UpdateParameters> <asp:Parameter Name=\"Password\" Type=\"String\" /> <asp:Parameter Name=\"HolderNo\" Type=\"String\" /> </UpdateParameters> <InsertParameters> <asp:Parameter Name=\"HolderNo\" /> <asp:ControlParameter ControlID=\"TextBox2\" Name=\"Password\" PropertyName=\"Text\" Type=\"String\" / > </InsertParameters> </asp:SqlDataSource> <br /> </td> </tr> <tr> <td class=\"style3\" colspan=\"2\"> <asp:SqlDataSource ID=\"SqlDataSource2\" runat=\"server\" ConnectionString=\"<%ConnectionStrings:JPRCnewConnectionString %>\" DeleteCommand=\"DELETE FROM [SHARE_news] WHERE [NewsId] = @NewsId\" InsertCommand=\"INSERT INTO [SHARE_news] ([NewsId], [NewsTitle], [NewsImg], [NewsFull], [NewsStatus], [NewsEntry], [NewsEntryDateAndTime], [NewsDate]) VALUES (@NewsId, @NewsTitle, @NewsImg, @NewsFull, @NewsStatus, @NewsEntry, @NewsEntryDateAndTime, @NewsDate)\" SelectCommand=\"SELECT * FROM [SHARE_news]\" UpdateCommand=\"UPDATE [SHARE_news] SET [NewsTitle] = @NewsTitle, [NewsImg] = @NewsImg, [NewsFull] = @NewsFull, [NewsStatus] = @NewsStatus, [NewsEntry] = @NewsEntry, [NewsEntryDateAndTime] = @NewsEntryDateAndTime, [NewsDate] = @NewsDa te WHERE [NewsId] = @NewsId\"> <DeleteParameters> <asp:Parameter Name=\"NewsId\" Type=\"Int32\" /> </DeleteParameters> < ;UpdateParameters> <asp:Parameter Name=\"NewsTitle\" Type=\"String\" /> <asp:Parameter Name=\"NewsImg\" Type=\"String\" /> <asp:Parameter Name=\"NewsFull\" Type=\"String\" /> <asp:Parameter Name=\"NewsStatus\" Type=\"String\" /> <asp:Parameter Name=\"NewsEntry\" Type=\"String\" /> <asp:Parameter Name=\"NewsEntryDateAndTime\" Type=\"DateTime\" /> <asp:Parameter Name=\"NewsDate\" Type=\"String\" /> <asp:Parameter Name=\"NewsId\" Type=\"Int32\" /> </UpdateParameters> <InsertParameters> <asp:Parameter Name=\"NewsId\" Type=\"Int32\" /> <asp:Parameter Name=\"NewsTitle\" Type=\"String\" /> <asp:Pa rameter Name=\"NewsImg\" Type=\"String\" /> <asp:Parameter Name=\"NewsFull\" Type=\"String\" /> <asp:Parameter Name=\"NewsStatus\" Type=\"String\" /> <asp:Parameter Name=\"NewsEntry\" Type=\"String\" /> <asp:Parameter Name=\"NewsEntryDateAndTime\" Type=\"DateTime\" /> <asp:Parameter Name=\"NewsDate\" Type=\"String\" /> </InsertParameters> </asp:SqlDataSource> <br /> </td> </tr> <tr> <td class=\"style3\" colspan=\"2\"> <asp:SqlDataSource ID=\"SqlDataSource3\" runat=\"ser ver\" ConnectionString=\"<%ConnectionStrings:JPRCnewConnectionString %>\" DeleteCommand=\"DELETE FROM [SH_events] WHERE [eventID] = @eventID\" InsertCommand=\"INSERT INTO [SH_events] ([eventID], [eventDate], [eventTitle], [eventdesc]) VALUES (@eventID, @eventDate, @eventTitle, @eventdesc)\" SelectCommand=\"SELECT * FROM [SH_events]\" UpdateCommand=\"UPDATE [SH_events] SET [eventDate] = @eventDate, [eventTitle] = @eventTitle, [eventdesc] = @eventdesc WHERE [eventID] = @eventID\"> <DeleteParameters> <asp:Parameter Name=\"eventID\" Type=\"Int32\" /> </DeleteParameters> <UpdateParameters> <asp:Parameter DbType=\"Date\" Name=\"eventDate\" /> <asp:Parameter Name=\"eventTitle\" Type=\"String\" /> <asp:Parameter Name=\"eventdesc\" Type=\"String\" /> <asp:Parameter Name=\"eventID\" Type=\"Int32\" /> </UpdateParameters> <InsertParameters> <asp:Parameter Name=\"eventID\" Type=\"Int32\" /> <asp:Parameter DbType=\"Date\" Name=\"eventDate\" /> <asp:Parameter Name=\"eventTitle\" Type=\"String\" /> <asp:Parameter Name=\"eventdesc\" Type=\"String\" /> </InsertParameters> </asp:SqlDataSo urce> </td> </tr> <tr> <td class=\"style3\" colspan=\"2\"> <asp:SqlDataSource ID=\"SqlDataSource4\" runat=\"server\" ConnectionString=\"<%Hi alli have created admin screen in order to review data of a users portal serves them as a website using asp.netin this page admin first choose the table to view it from a dropdownlistunder his choice the grid view display the data with a details view control to insert a new recordi have created 4 sqldatasourses bounded to 4 tablesand after the admin choose the table name from the dropdownlist the grid view fill with its datamy problem is update not working at all its not affect the dataaspx.vb page:Imports Microsoft.VisualBasicImports System.Data.SqlClientImports System.DrawingImports System.Drawing.ImagingImports System.Drawing.TextImports System.DataPartial Public Class admin Inherits System.Web.UI.Page Dim cls As New clsMainFunctions Public ReadOnly sqlCN1 As New SqlConnection(ConfigurationManager.ConnectionStrings("JPRCCS").ConnectionString) Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load GridView1.DataSource = SqlDataSource1 GridView1.DataBind() DetailsView1.DataSourceID = "SqlDataSource1" DetailsView1.DataBind() If Not IsPostBack Then GridView1.DataBind() DetailsView1.DataBind() End If End Sub Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles DropDownList1.SelectedIndexChanged Dim tablename As String = "" Select Case DropDownList1.SelectedIndex Case 0 tablename = "TB_ShareHolders_RG" GridView1.DataSource = SqlDataSource1 GridView1.DataBind() DetailsView1.DataSourceID = "SqlDataSource1" DetailsView1.DataBind() Case 1 tablename = "SHARE_news" GridView1.DataSource = SqlDataSource2 GridView1.DataBind() DetailsView1.DataSourceID = "SqlDataSource2" DetailsView1.DataBind() Case 2 tablename = "SH_events" GridView1.DataSource = SqlDataSource3 GridView1.DataBind() DetailsView1.DataSourceID = "SqlDataSource3" DetailsView1.DataBind() Case 3 tablename = "tb_Announcement" GridView1.DataSource = SqlDataSource4 GridView1.DataBind() DetailsView1.DataSourceID = "SqlDataSource4" DetailsView1.DataBind() Case 4 tablename = "SharePrice" GridView1.DataSource = SqlDataSource5 GridView1.DataBind() DetailsView1.DataSourceID = "SqlDataSource5" DetailsView1.DataBind() End Select End Sub Private Sub GridView1_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles GridView1.PageIndexChanging GridView1.PageIndex = e.NewPageIndex End Sub Private Sub GridView1_RowCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowCreated End Sub Private Sub GridView1_RowDeleting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles GridView1.RowDeleting GridView1.DataBind() End Sub Private Sub GridView1_RowEditing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles GridView1.RowEditing GridView1.EditIndex = e.NewEditIndex GridView1.DataBind() End Sub Private Sub GridView1_RowUpdated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdatedEventArgs) Handles GridView1.RowUpdated GridView1.EditIndex = -1 'Bind the grid GridView1.DataBind() End Sub Private Sub GridView1_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles GridView1.RowUpdating GridView1.EditIndex = -1 'Bind the grid GridView1.DataBind() End Sub Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles GridView1.SelectedIndexChanged End SubEnd Class.aspx page:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" ><head runat="server"> <title></title> <style type="text/css"> .style1 { width: 100%; } .style2 { height: 151px; } .style3 {} </style></head><body> <form id="form1" runat="server"> <div> <table class="style1"> <tr> <td class="style2" colspan="2"> </td> </tr> <tr> <td class="style3"> </td> <td> </td> </tr> <tr> <td class="style3"> <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"> <asp:ListItem>Users</asp:ListItem> <asp:ListItem>News</asp:ListItem> <asp:ListItem>Events</asp:ListItem> <asp:ListItem>Announcements</asp:ListItem> <asp:ListItem>Share Price</asp:ListItem> </asp:DropDownList> <br /> </td> <td> </td> </tr> <tr> <td class="style3" colspan="2"> <asp:GridView ID="GridView1" runat="server" AllowPaging="True" CellPadding="4" ForeColor="#333333" GridLines="None" AllowSorting="True" AutoGenerateEditButton="True" AutoGenerateSelectButton="True" AutoGenerateDeleteButton="True" Height="310px" Width="1060px"> <RowStyle BackColor="#E3EAEB" /> <Columns> <asp:CommandField /> </Columns> <FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" /> <PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" /> <SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" /> <HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" /> <EditRowStyle BackColor="#7C6F57" /> <AlternatingRowStyle BackColor="White" /> </asp:GridView> <asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateInsertButton="True" Height="76px" Width="1064px" BackColor="White" BorderColor="#E7E7FF" BorderStyle="None" BorderWidth="1px" CellPadding="3" GridLines="Horizontal"> <FooterStyle BackColor="#B5C7DE" ForeColor="#4A3C8C" /> <RowStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" /> <PagerStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" HorizontalAlign="Right" /> <HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#F7F7F7" /> <EditRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="#F7F7F7" /> <AlternatingRowStyle BackColor="#F7F7F7" /> </asp:DetailsView> <asp:Label ID="ErrorMessageLabel" runat="server"></asp:Label> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:JPRCnewConnectionString %>" DeleteCommand="DELETE FROM [TB_ShareHolders_RG] WHERE [HolderNo] = @HolderNo" InsertCommand="INSERT INTO [TB_ShareHolders_RG] ([HolderNo], [Password]) VALUES (@HolderNo, @Password)" SelectCommand="SELECT [HolderNo], [Password] FROM [TB_ShareHolders_RG]" UpdateCommand="UPDATE [TB_ShareHolders_RG] SET [Password] = @Password WHERE [HolderNo] = @HolderNo"> <DeleteParameters> <asp:Parameter Name="HolderNo" Type="String" /> </DeleteParameters> <UpdateParameters> <asp:Parameter Name="Password" Type="String" /> <asp:Parameter Name="HolderNo" Type="String" /> </UpdateParameters> <InsertParameters> <asp:Parameter Name="HolderNo" /> <asp:ControlParameter ControlID="TextBox2" Name="Password" PropertyName="Text" Type="String" /> </InsertParameters> </asp:SqlDataSource> <br /> </td> </tr> <tr> <td class="style3" colspan="2"> <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:JPRCnewConnectionString %>" DeleteCommand="DELETE FROM [SHARE_news] WHERE [NewsId] = @NewsId" InsertCommand="INSERT INTO [SHARE_news] ([NewsId], [NewsTitle], [NewsImg], [NewsFull], [NewsStatus], [NewsEntry], [NewsEntryDateAndTime], [NewsDate]) VALUES (@NewsId, @NewsTitle, @NewsImg, @NewsFull, @NewsStatus, @NewsEntry, @NewsEntryDateAndTime, @NewsDate)" SelectCommand="SELECT * FROM [SHARE_news]" UpdateCommand="UPDATE [SHARE_news] SET [NewsTitle] = @NewsTitle, [NewsImg] = @NewsImg, [NewsFull] = @NewsFull, [NewsStatus] = @NewsStatus, [NewsEntry] = @NewsEntry, [NewsEntryDateAndTime] = @NewsEntryDateAndTime, [NewsDate] = @NewsDate WHERE [NewsId] = @NewsId"> <DeleteParameters> <asp:Parameter Name="NewsId" Type="Int32" /> </DeleteParameters> <UpdateParameters> <asp:Parameter Name="NewsTitle" Type="String" /> <asp:Parameter Name="NewsImg" Type="String" /> <asp:Parameter Name="NewsFull" Type="String" /> <asp:Parameter Name="NewsStatus" Type="String" /> <asp:Parameter Name="NewsEntry" Type="String" /> <asp:Parameter Name="NewsEntryDateAndTime" Type="DateTime" /> <asp:Parameter Name="NewsDate" Type="String" /> <asp:Parameter Name="NewsId" Type="Int32" /> </UpdateParameters> <InsertParameters> <asp:Parameter Name="NewsId" Type="Int32" /> <asp:Parameter Name="NewsTitle" Type="String" /> <asp:Parameter Name="NewsImg" Type="String" /> <asp:Parameter Name="NewsFull" Type="String" /> <asp:Parameter Name="NewsStatus" Type="String" /> <asp:Parameter Name="NewsEntry" Type="String" /> <asp:Parameter Name="NewsEntryDateAndTime" Type="DateTime" /> <asp:Parameter Name="NewsDate" Type="String" /> </InsertParameters> </asp:SqlDataSource> <br /> </td> </tr> <tr> <td class="style3" colspan="2"> <asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:JPRCnewConnectionString %>" DeleteCommand="DELETE FROM [SH_events] WHERE [eventID] = @eventID" InsertCommand="INSERT INTO [SH_events] ([eventID], [eventDate], [eventTitle], [eventdesc]) VALUES (@eventID, @eventDate, @eventTitle, @eventdesc)" SelectCommand="SELECT * FROM [SH_events]" UpdateCommand="UPDATE [SH_events] SET [eventDate] = @eventDate, [eventTitle] = @eventTitle, [eventdesc] = @eventdesc WHERE [eventID] = @eventID"> <DeleteParameters> <asp:Parameter Name="eventID" Type="Int32" /> </DeleteParameters> <UpdateParameters> <asp:Parameter DbType="Date" Name="eventDate" /> <asp:Parameter Name="eventTitle" Type="String" /> <asp:Parameter Name="eventdesc" Type="String" /> <asp:Parameter Name="eventID" Type="Int32" /> </UpdateParameters> <InsertParameters> <asp:Parameter Name="eventID" Type="Int32" /> <asp:Parameter DbType="Date" Name="eventDate" /> <asp:Parameter Name="eventTitle" Type="String" /> <asp:Parameter Name="eventdesc" Type="String" /> </InsertParameters> </asp:SqlDataSource> </td> </tr> <tr> <td class="style3" colspan="2"> <asp:SqlDataSource ID="SqlDataSource4" runat="server" ConnectionString="<%$ ConnectionStrings:JPRCnewConnectionString %>" DeleteCommand="DELETE FROM [tb_Announcement] WHERE [AnnoucmentID] = @AnnoucmentID" InsertCommand="INSERT INTO [tb_Announcement] ([Ann_Title], [Ann_Des], [Ann_Date], [Ann_Status], [Ann_Lang]) VALUES (@Ann_Title, @Ann_Des, @Ann_Date, @Ann_Status, @Ann_Lang)" SelectCommand="SELECT * FROM [tb_Announcement]" UpdateCommand="UPDATE [tb_Announcement] SET [Ann_Title] = @Ann_Title, [Ann_Des] = @Ann_Des, [Ann_Date] = @Ann_Date, [Ann_Status] = @Ann_Status, [Ann_Lang] = @Ann_Lang WHERE [AnnoucmentID] = @AnnoucmentID"> <DeleteParameters> <asp:Parameter Name="AnnoucmentID" Type="Int32" /> </DeleteParameters> <UpdateParameters> <asp:Parameter Name="Ann_Title" Type="String" /> <asp:Parameter Name="Ann_Des" Type="String" /> <asp:Parameter Name="Ann_Date" DbType="Date" /> <asp:Parameter Name="Ann_Status" Type="String" /> <asp:Parameter Name="Ann_Lang" Type="String" /> <asp:Parameter Name="AnnoucmentID" Type="Int32" /> </UpdateParameters> <InsertParameters> <asp:Parameter Name="Ann_Title" Type="String" /> <asp:Parameter Name="Ann_Des" Type="String" /> <asp:Parameter DbType="Date" Name="Ann_Date" /> <asp:Parameter Name="Ann_Status" Type="String" /> <asp:Parameter Name="Ann_Lang" Type="String" /> </InsertParameters> </asp:SqlDataSource> </td> </tr> <tr> <td class="style3" colspan="2"> <asp:SqlDataSource ID="SqlDataSource5" runat="server" ConnectionString="<%$ ConnectionStrings:JPRCnewConnectionString %>" DeleteCommand="DELETE FROM [SharePrice] WHERE [ID] = @ID" InsertCommand="INSERT INTO [SharePrice] ([shareprice], [date]) VALUES (@shareprice, @date)" SelectCommand="SELECT * FROM [SharePrice]" UpdateCommand="UPDATE [SharePrice] SET [shareprice] = @shareprice, [date] = @date WHERE [ID] = @ID"> <DeleteParameters> <asp:Parameter Name="ID" Type="Int32" /> </DeleteParameters> <UpdateParameters> <asp:Parameter Name="shareprice" Type="Int32" /> <asp:Parameter Name="date" DbType="Date" /> <asp:Parameter Name="ID" Type="Int32" /> </UpdateParameters> <InsertParameters> <asp:Parameter Name="shareprice" Type="Int32" /> <asp:Parameter Name="date" DbType="Date" /> </InsertParameters> </asp:SqlDataSource> </td> </tr> </table> </div> </form></body></html> 解决方案 ConnectionStrings:JPRCnewConnectionString %>" DeleteCommand="DELETE FROM [TB_ShareHolders_RG] WHERE [HolderNo] = @HolderNo" InsertCommand="INSERT INTO [TB_ShareHolders_RG] ([HolderNo], [Password]) VALUES (@HolderNo, @Password)" SelectCommand="SELECT [HolderNo], [Password] FROM [TB_ShareHolders_RG]" UpdateCommand="UPDATE [TB_ShareHolders_RG] SET [Password] = @Password WHERE [HolderNo] = @HolderNo"> <DeleteParameters> <asp:Parameter Name="HolderNo" Type="String" /> </DeleteParameters> <UpdateParameters> <asp:Parameter Name="Password" Type="String" /> <asp:Parameter Name="HolderNo" Type="String" /> </UpdateParameters> <InsertParameters> <asp:Parameter Name="HolderNo" /> <asp:ControlParameter ControlID="TextBox2" Name="Password" PropertyName="Text" Type="String" /> </InsertParameters> </asp:SqlDataSource> <br /> </td> </tr> <tr> <td class="style3" colspan="2"> <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%ConnectionStrings:JPRCnewConnectionString %>" DeleteCommand="DELETE FROM [SHARE_news] WHERE [NewsId] = @NewsId" InsertCommand="INSERT INTO [SHARE_news] ([NewsId], [NewsTitle], [NewsImg], [NewsFull], [NewsStatus], [NewsEntry], [NewsEntryDateAndTime], [NewsDate]) VALUES (@NewsId, @NewsTitle, @NewsImg, @NewsFull, @NewsStatus, @NewsEntry, @NewsEntryDateAndTime, @NewsDate)" SelectCommand="SELECT * FROM [SHARE_news]" UpdateCommand="UPDATE [SHARE_news] SET [NewsTitle] = @NewsTitle, [NewsImg] = @NewsImg, [NewsFull] = @NewsFull, [NewsStatus] = @NewsStatus, [NewsEntry] = @NewsEntry, [NewsEntryDateAndTime] = @NewsEntryDateAndTime, [NewsDate] = @NewsDate WHERE [NewsId] = @NewsId"> <DeleteParameters> <asp:Parameter Name="NewsId" Type="Int32" /> </DeleteParameters> <UpdateParameters> <asp:Parameter Name="NewsTitle" Type="String" /> <asp:Parameter Name="NewsImg" Type="String" /> <asp:Parameter Name="NewsFull" Type="String" /> <asp:Parameter Name="NewsStatus" Type="String" /> <asp:Parameter Name="NewsEntry" Type="String" /> <asp:Parameter Name="NewsEntryDateAndTime" Type="DateTime" /> <asp:Parameter Name="NewsDate" Type="String" /> <asp:Parameter Name="NewsId" Type="Int32" /> </UpdateParameters> <InsertParameters> <asp:Parameter Name="NewsId" Type="Int32" /> <asp:Parameter Name="NewsTitle" Type="String" /> <asp:Parameter Name="NewsImg" Type="String" /> <asp:Parameter Name="NewsFull" Type="String" /> <asp:Parameter Name="NewsStatus" Type="String" /> <asp:Parameter Name="NewsEntry" Type="String" /> <asp:Parameter Name="NewsEntryDateAndTime" Type="DateTime" /> <asp:Parameter Name="NewsDate" Type="String" /> </InsertParameters> </asp:SqlDataSource> <br /> </td> </tr> <tr> <td class="style3" colspan="2"> <asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%ConnectionStrings:JPRCnewConnectionString %>" DeleteCommand="DELETE FROM [SH_events] WHERE [eventID] = @eventID" InsertCommand="INSERT INTO [SH_events] ([eventID], [eventDate], [eventTitle], [eventdesc]) VALUES (@eventID, @eventDate, @eventTitle, @eventdesc)" SelectCommand="SELECT * FROM [SH_events]" UpdateCommand="UPDATE [SH_events] SET [eventDate] = @eventDate, [eventTitle] = @eventTitle, [eventdesc] = @eventdesc WHERE [eventID] = @eventID"> <DeleteParameters> <asp:Parameter Name="eventID" Type="Int32" /> </DeleteParameters> <UpdateParameters> <asp:Parameter DbType="Date" Name="eventDate" /> <asp:Parameter Name="eventTitle" Type="String" /> <asp:Parameter Name="eventdesc" Type="String" /> <asp:Parameter Name="eventID" Type="Int32" /> </UpdateParameters> <InsertParameters> <asp:Parameter Name="eventID" Type="Int32" /> <asp:Parameter DbType="Date" Name="eventDate" /> <asp:Parameter Name="eventTitle" Type="String" /> <asp:Parameter Name="eventdesc" Type="String" /> </InsertParameters> </asp:SqlDataSource> </td> </tr> <tr> <td class="style3" colspan="2"> <asp:SqlDataSource ID="SqlDataSource4" runat="server" ConnectionString="<% 这篇关于asp.net中的gridview更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-23 23:38