我的网站的工具:
- 视觉工作室 2010
- SQL 管理工作室
- 网
- 视觉基础网
我正在使用 GridView。由于我的搜索代码,我无法使用 GridView 提供的自动删除功能。
我点击了 GridView,说“添加新列”并添加了一个复选框列。
我希望能够选中一个或多个框并选择一个按钮,该按钮将使用存储过程从数据库中删除这些行。
下面是我的代码的 ASP.net 部分
默认.aspx
<%@ Page Title="Home Page" Language="vb" MasterPageFile="~/Site.Master" AutoEventWireup="false" CodeBehind="Default.aspx.vb" Inherits="ContactList._Default" %>
<%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="asp" %>
<%-- CONNECTION STRING--%>
<%--string Connection = "server=Local; uid=sa; pwd=; database=TGMInfo; Connect Timeout=10000";--%>
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
<link href="Styles/Site.css" rel="stylesheet" type="text/css" />
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<h2>
Welcome to THE TGM CONTACTS SITE</h2>
<p>
</p>
<p></p>
<center>
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</asp:ToolkitScriptManager>
Add a new record to the database<br />
<br />
<%--Text boxes for First Name, Last Name and Main Phone Number--%>
<asp:Label ID="lblFirstName" runat="server" Text="First Name:"></asp:Label>
<asp:TextBox ID="txtFirstName" runat="server" Width="160px"></asp:TextBox>
<asp:Label ID="LblLastName" runat="server" Text="Last Name:"></asp:Label>
<asp:TextBox ID="txtLastName" runat="server" Width="160px"></asp:TextBox>
<asp:Label ID="lblMainPhone" runat="server" Text="Main Phone #:"></asp:Label>
<asp:TextBox ID="txtMainPhone" runat="server" Width="160px"></asp:TextBox>
<asp:MaskedEditExtender ID="txtMainPhone_MaskedEditExtender" runat="server"
ErrorTooltipEnabled="True" Mask="(999) 999-9999" MaskType="Number"
TargetControlID="txtMainPhone">
</asp:MaskedEditExtender>
<br />
<br />
<%--Button adds information from the text fields to the SQL Database--%>
<asp:Button ID="btnAdd" runat="server" Text="Add Record" />
<br />
<br />
<br />
Search by Last Name<br />
<asp:Label ID="lblQuery" runat="server" Text="Last Name:"></asp:Label>
<asp:TextBox ID="txtQuery" runat="server" ToolTip="Search by last name"></asp:TextBox>
<br />
<br />
<asp:Button ID="BtnQuery" runat="server" Text="Search" />
<br />
</center>
<p>
</p>
<p>
</p>
<center>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataKeyNames="EmpId"
EmptyDataText="There are no data records to display." CellPadding="4"
ForeColor="#333333" GridLines="None" Height="136px" Width="299px">
<AlternatingRowStyle BackColor="White" />
<Columns>
<%-- <asp:BoundField DataField="MainPhoneNumber" HeaderText="Main Phone Number"
SortExpression="MainPhoneNumber" />--%>
<asp:BoundField DataField="EmpId" HeaderText="EmpId" ReadOnly="True"
SortExpression="EmpId" Visible="False" />
<asp:BoundField DataField="FirstName" HeaderText="First Name"
SortExpression="FirstName" />
<asp:BoundField DataField="LastName" HeaderText="Last Name"
SortExpression="LastName" />
<asp:TemplateField HeaderText="Main Phone Number">
<ItemTemplate>
<asp:Literal ID="litPhone" runat="server" Text='<%# string.Format("{0:(###) ###-####}", Int64.Parse(Eval("MainPhoneNumber").ToString())) %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Check For Deletion">
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" />
</ItemTemplate>
<EditItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" />
</EditItemTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
<RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
<SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
<SortedAscendingCellStyle BackColor="#FDF5AC" />
<SortedAscendingHeaderStyle BackColor="#4D0000" />
<SortedDescendingCellStyle BackColor="#FCF6C0" />
<SortedDescendingHeaderStyle BackColor="#820000" />
</asp:GridView>
<p>
<center>
<asp:Button ID="Button1" runat="server" Text="Delete Selected Rows"
ToolTip="Check desired rows and click this button for deletion" />
</p>
<p>
</p>
</center>
</asp:Content>
我想我发布了我需要的所有内容,如果没有,我可以发布更多。到目前为止,我没有发布代码隐藏 (visual basic.net) 或 2 个存储过程。我对 vb.net/asp.net/存储过程很陌生。