GridView的'PendingRecordsGridview'触发了事件RowDeleting,它没有被处理 [英] The GridView 'PendingRecordsGridview' fired event RowDeleting which wasn't handled
问题描述
< asp 我在谷歌搜索了一个简单的方法来删除一个记录, :templatefield HeaderText =删除>
< ItemTemplate>
< asp:Button ID =deleteButtonrunat =serverCommandName =DeleteText =DeleteOnClientClick =return confirm('您确定要删除此用户?'); />
< / ItemTemplate>
< / asp:templatefield>
但是当我运行它并单击删除并单击是确认。这个错误出现:
GridView的PendingRecordsGridview触发了事件RowDeleting,它没有被处理。
有人帮助我:(我也试过添加这段代码
以下是我的gridview完整代码:
< asp:GridView OnPageIndexChanging =PendingRecordsGridview_PageIndexChangingID =PendingRecordsGridviewrunat =serverAutoGenerateColumns =FalseDataKeyNames =IDOnRowcommand =PendingRecordsGridview_RowCommandDataSourceID =sd1BorderStyle = RidgeBackColor =WhiteBorderColor =BlackBorderWidth =3pxCellPadding =4Width =1070pxPageSize =2AllowPaging =True>
< RowStyle ForeColor = #003399HorizontalAlign =Center/>
< Columns>
< asp:templatefield HeaderText =Accept>
< ItemTemplate>
< asp :Button CommandArgument ='<%#Bi nd(id)%>'ID =Button1runat =serverCausesValidation =falseCommandName =acceptText =Accept/>
< / ItemTemplate>
< / asp:templatefield>
< asp:templatefield HeaderText =Delete>
< ItemTemplate>
< asp:Button ID =deleteButtonrunat =serverCommandName =DeleteText =DeleteOnClientClick =return confirm('您确定要删除此用户?'); />
< / ItemTemplate>
< / asp:templatefield>
< asp:templatefield HeaderText =IDSortExpression =ID>
< EditItemTemplate>
< asp:Label ID =Label1runat =serverText ='<%#Eval(ID)%>'>
< / asp:标签>
< / EditItemTemplate>
< ItemTemplate>
< asp:Label ID =Label2runat =serverText ='<%#Bind(ID)%>'>
< / asp:标签>
< / ItemTemplate>
< / asp:templatefield>
< asp:templatefield HeaderText =First NameSortExpression =FirstName>
< EditItemTemplate>
< asp:TextBox ID =TextBox1runat =serverText ='<%#Bind(FirstName)%>'>
< / asp:TextBox>
< / EditItemTemplate>
< ItemTemplate>
< asp:Label ID =Label3runat =serverText ='<%#Bind(FirstName)%>'>
< / asp:标签>
< / ItemTemplate>
< / asp:templatefield>
< asp:templatefield HeaderText =Last NameSortExpression =LastName>
< EditItemTemplate>
< asp:TextBox ID =TextBox1runat =serverText ='<%#Bind(LastName)%>'>
< / asp:TextBox>
< / EditItemTemplate>
< ItemTemplate>
< asp:Label ID =Label4runat =serverText ='<%#Bind(LastName)%>'>
< / asp:标签>
< / ItemTemplate>
< / asp:templatefield>
< asp:templatefield HeaderText =中间名SortExpression =MiddleLastName>
< EditItemTemplate>
< asp:TextBox ID =TextBox1runat =serverText ='<%#Bind(MiddleName)%>'>
< / asp:TextBox>
< / EditItemTemplate>
< ItemTemplate>
< asp:Label ID =Label5runat =serverText ='<%#Bind(MiddleName)%>'>
< / asp:标签>
< / ItemTemplate>
< / asp:templatefield>
< asp:templatefield HeaderText =AddressSortExpression =Address>
< EditItemTemplate>
< asp:TextBox ID =TextBox1runat =serverText ='<%#Bind(Address)%>>
< / asp:TextBox>
< / EditItemTemplate>
< ItemTemplate>
< asp:Label ID =Label6runat =serverText ='<%#Bind(Address)%>'>
< / asp:标签>
< / ItemTemplate>
< / asp:templatefield>
< asp:templatefield HeaderText =GenderSortExpression =Gender>
< EditItemTemplate>
< asp:TextBox ID =TextBox1runat =serverText ='<%#Bind(Gender)%>'>
< / asp:TextBox>
< / EditItemTemplate>
< ItemTemplate>
< asp:Label ID =Label7runat =serverText ='<%#Bind(Gender)%>'>
< / asp:标签>
< / ItemTemplate>
< / asp:templatefield>
< asp:templatefield HeaderText =联系电话号码的SortExpression = ContactNumber >
< EditItemTemplate>
< asp:TextBox ID =TextBox1runat =serverText ='<%#Bind(ContactNumber)%>'>
< / asp:TextBox>
< / EditItemTemplate>
< ItemTemplate>
< asp:Label ID =Label18runat =serverText ='<%#Bind(ContactNumber)%>'>
< / asp:标签>
< / ItemTemplate>
< / asp:templatefield>
< asp:templatefield HeaderText =板号的SortExpression = PlateNumber >
< EditItemTemplate>
< asp:TextBox ID =TextBox1runat =serverText ='<%#Bind(PlateNumber)%>'>
< / asp:TextBox>
< / EditItemTemplate>
< ItemTemplate>
< asp:Label ID =Label19runat =serverText ='<%#Bind(PlateNumber)%>'>
< / asp:标签>
< / ItemTemplate>
< / asp:templatefield>
< asp:templatefield HeaderText =Mobile ColorSortExpression =Color>
< EditItemTemplate>
< asp:TextBox ID =TextBox1runat =serverText ='<%#Bind(Color)%>'>
< / asp:TextBox>
< / EditItemTemplate>
< ItemTemplate>
< asp:Label ID =Label11runat =serverText ='<%#Bind(Color)%>'>
< / asp:标签>
< / ItemTemplate>
< / asp:templatefield>
< asp:templatefield HeaderText =BrandSortExpression =Brand>
< EditItemTemplate>
< asp:TextBox ID =TextBox1runat =serverText ='<%#Bind(Brand)%>'>
< / asp:TextBox>
< / EditItemTemplate>
< ItemTemplate>
< asp:Label ID =Label12runat =serverText ='<%#Bind(Brand)%>'>
< / asp:标签>
< / ItemTemplate>
< / asp:templatefield>
< asp:templatefield HeaderText =Liscenced No.的SortExpression = LiscensedNumber >
< EditItemTemplate>
< asp:TextBox ID =TextBox1runat =serverText ='<%#Bind(LiscensedNumber)%>'>
< / asp:TextBox>
< / EditItemTemplate>
< ItemTemplate>
< asp:Label ID =Label10runat =serverText ='<%#Bind(LiscensedNumber)%>'>
< / asp:标签>
< / ItemTemplate>
< / asp:templatefield>
< asp:TemplateField>
< HeaderTemplate>图片< / HeaderTemplate>
< ItemTemplate>
< img src ='data:image / jpg; base64,<%#Eval(Image)!= System.DBNull.Value? Convert.ToBase64String((byte [])Eval(Image)):string.Empty%>'alt =imageheight =85width =85/>
< / ItemTemplate>
< / asp:TemplateField> < /栏>
< FooterStyle BackColor =#99CCCCForeColor =#003399/>
< EmptyDataTemplate>
不需要申请!
< / EmptyDataTemplate>
< SelectedRowStyle BackColor =#009999Font-Bold =TrueForeColor =#CCFF99/>
< HeaderStyle BackColor =#999999Font-Bold =TrueForeColor =#003399HorizontalAlign =Center/>
< AlternatingRowStyle BorderColor =BlackBorderWidth =3pxBorderStyle =Ridge/>
< / asp:GridView>
< / td>
< td style =height:282px>& nbsp;< / td>
< / tr>
< tr>
< td>& nbsp;< / td>
< td>& nbsp;< / td>
< td>& nbsp;< / td>
< td>& nbsp;< / td>
< td>& nbsp;< / td>
< td style =height:37px>& nbsp;< / td>
< / tr>
< tr>
< td>& nbsp;< / td>
< td>& nbsp;< / td>
< td>& nbsp;< / td>
< td valign =top>
< asp:SqlDataSource runat =serverid =sd1ProviderName =<%$ ConnectionStrings:ConnectionString.ProviderName%> ConnectionString =<%$ ConnectionStrings:ConnectionString%> SelectCommand =SELECT * FROM [PendingRecords]DeleteCommand =DELETE FROM [PendingRecords] WHERE [ID] =? InsertCommand =INSERT INTO [PendingRecords]([用户名],[密码],[名字],[姓氏],[中间名],[地址],[性别],[联系号码] [板号] [颜色]品牌],[LiscensedNumber])VALUES(?,?,?,?,?,?,?,?,?,?,?)UpdateCommand =UPDATE [PendingRecords] SET [Username] =?,[Password ] =?,[FirstName] =?,[LastName] =?,[MiddleName] =?,[Address] =?,[Gender] =?,[ContactNumber] =?,[PlateNumber] =?,[Color] =? ?,[Brand] =?,[LiscensedNumber] =?WHERE [ID] =?>
< DeleteParameters>
< asp:parameter Name =IDType =Int32/>
< / DeleteParameters>
< UpdateParameters>
< asp:parameter Name =UsernameType =String/>
< asp:parameter Name =PasswordType =String/>
< asp:parameter Name =FirstNameType =String/>
< asp:parameter Name =LastNameType =String/>
< asp:parameter Name =MiddleNameType =String/>
< asp:parameter Name =AddressType =String/>
< asp:parameter Name =GenderType =String/>
< asp:parameter Name =ContactNumberType =String/>
< asp:parameter Name =PlateNumberType =String/>
< asp:parameter Name =ColorType =String/>
< asp:parameter Name =BrandType =String/>
< asp:parameter Name =LiscensedNumberType =String/>
< asp:parameter Name =IDType =Int32/>
< / UpdateParameters>
< InsertParameters>
< asp:parameter Name =UsernameType =String/>
< asp:parameter Name =PasswordType =String/>
< asp:parameter Name =FirstNameType =String/>
< asp:parameter Name =LastNameType =String/>
< asp:parameter Name =MiddleNameType =String/>
< asp:parameter Name =AddressType =String/>
< asp:parameter Name =GenderType =String/>
< asp:parameter Name =ContactNumberType =String/>
< asp:parameter Name =PlateNumberType =String/>
< asp:parameter Name =ColorType =String/>
< asp:parameter Name =BrandType =String/>
< asp:parameter Name =LiscensedNumberType =String/>
< / InsertParameters>
< / asp:SqlDataSource>
< / td>
< td>& nbsp;< / td>
< td style =height:33px>& nbsp;< / td>
< / tr>
< tr>
< td style =width:32px>& nbsp;< / td>
< td style =width:8px>& nbsp;< / td>
< td style =width:87px>& nbsp;< / td>
< td style =width:542px>& nbsp;< / td>
< td style =width:447px>& nbsp;< / td>
< td style =height:83px; width:34px;>& nbsp;< / td>
< / tr>
< / table>
请修改您的标记和代码以包含 OnRowDeleting
事件
< asp:GridView OnPageIndexChanging =PendingRecordsGridview_PageIndexChanging PendingRecordsGridviewrunat =serverAutoGenerateColumns =FalseDataKeyNames =IDOnRowcommand =PendingRecordsGridview_RowCommandDataSourceID =sd1BorderStyle =RidgeBackColor =WhiteBorderColor =BlackBorderWidth =3pxCellPadding = 4Width =1070pxPageSize =2AllowPaging =True>
< RowStyle ForeColor =#003399HorizontalAlign =CenterOnRowDeleting =PendingRecordsGridview_RowDeleting/>
在后面的代码中加入这个方法。
< pre $
public void PendingRecordsGridview_RowDeleting(Object sender,GridViewDeleteEventArgs e)
{
}
I've searched in google there's an easy way to delete a record with confirmation using this code:
<asp:templatefield HeaderText="Delete">
<ItemTemplate>
<asp:Button ID="deleteButton" runat="server" CommandName="Delete" Text="Delete" OnClientClick="return confirm('Are you sure you want to delete this user?');" />
</ItemTemplate>
</asp:templatefield>
But when i run it and click delete and clicking "yes" to confirm. this error appears: The GridView 'PendingRecordsGridview' fired event RowDeleting which wasn't handled.
Somebody Help me :( i've also tried adding this code ``OnRowDeleting = "PendingRecordsGridview_RowDeleting" but no success! :(
Here's my gridview full code:
<asp:GridView OnPageIndexChanging="PendingRecordsGridview_PageIndexChanging" ID="PendingRecordsGridview" runat="server" AutoGenerateColumns="False" DataKeyNames="ID" OnRowcommand="PendingRecordsGridview_RowCommand" DataSourceID="sd1" BorderStyle="Ridge" BackColor="White" BorderColor="Black" BorderWidth="3px" CellPadding="4" Width="1070px" PageSize="2" AllowPaging="True">
<RowStyle ForeColor="#003399" HorizontalAlign="Center" />
<Columns>
<asp:templatefield HeaderText="Accept">
<ItemTemplate>
<asp:Button CommandArgument='<%# Bind("id") %>' ID="Button1" runat="server" CausesValidation="false" CommandName="accept" Text="Accept" />
</ItemTemplate>
</asp:templatefield>
<asp:templatefield HeaderText="Delete">
<ItemTemplate>
<asp:Button ID="deleteButton" runat="server" CommandName="Delete" Text="Delete" OnClientClick="return confirm('Are you sure you want to delete this user?');" />
</ItemTemplate>
</asp:templatefield>
<asp:templatefield HeaderText="ID" SortExpression="ID">
<EditItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("ID") %>'>
</asp:Label>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("ID") %>'>
</asp:Label>
</ItemTemplate>
</asp:templatefield>
<asp:templatefield HeaderText="First Name" SortExpression="FirstName">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("FirstName") %>'>
</asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Bind("FirstName") %>'>
</asp:Label>
</ItemTemplate>
</asp:templatefield>
<asp:templatefield HeaderText="Last Name" SortExpression="LastName">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("LastName") %>'>
</asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label4" runat="server" Text='<%# Bind("LastName") %>'>
</asp:Label>
</ItemTemplate>
</asp:templatefield>
<asp:templatefield HeaderText="Middle Name" SortExpression="MiddleLastName">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("MiddleName") %>'>
</asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label5" runat="server" Text='<%# Bind("MiddleName") %>'>
</asp:Label>
</ItemTemplate>
</asp:templatefield>
<asp:templatefield HeaderText="Address" SortExpression="Address">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Address") %>'>
</asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label6" runat="server" Text='<%# Bind("Address") %>'>
</asp:Label>
</ItemTemplate>
</asp:templatefield>
<asp:templatefield HeaderText="Gender" SortExpression="Gender">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Gender") %>'>
</asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label7" runat="server" Text='<%# Bind("Gender") %>'>
</asp:Label>
</ItemTemplate>
</asp:templatefield>
<asp:templatefield HeaderText="Contact No." SortExpression="ContactNumber">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("ContactNumber") %>'>
</asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label18" runat="server" Text='<%# Bind("ContactNumber") %>'>
</asp:Label>
</ItemTemplate>
</asp:templatefield>
<asp:templatefield HeaderText="Plate No." SortExpression="PlateNumber">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("PlateNumber") %>'>
</asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label19" runat="server" Text='<%# Bind("PlateNumber") %>'>
</asp:Label>
</ItemTemplate>
</asp:templatefield>
<asp:templatefield HeaderText="Mobile Color" SortExpression="Color">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Color") %>'>
</asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label11" runat="server" Text='<%# Bind("Color") %>'>
</asp:Label>
</ItemTemplate>
</asp:templatefield>
<asp:templatefield HeaderText="Brand" SortExpression="Brand">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Brand") %>'>
</asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label12" runat="server" Text='<%# Bind("Brand") %>'>
</asp:Label>
</ItemTemplate>
</asp:templatefield>
<asp:templatefield HeaderText="Liscenced No." SortExpression="LiscensedNumber">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("LiscensedNumber") %>'>
</asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label10" runat="server" Text='<%# Bind("LiscensedNumber") %>'>
</asp:Label>
</ItemTemplate>
</asp:templatefield>
<asp:TemplateField>
<HeaderTemplate>Image</HeaderTemplate>
<ItemTemplate>
<img src='data:image/jpg;base64,<%# Eval("Image") != System.DBNull.Value ? Convert.ToBase64String((byte[])Eval("Image")) : string.Empty %>' alt="image" height="85" width="85"/>
</ItemTemplate>
</asp:TemplateField> </Columns>
<FooterStyle BackColor="#99CCCC" ForeColor="#003399" />
<PagerStyle HorizontalAlign="Center" BackColor="#999999" ForeColor="#003399" />
<EmptyDataTemplate>
NO PENDING REQUEST!
</EmptyDataTemplate>
<SelectedRowStyle BackColor="#009999" Font-Bold="True" ForeColor="#CCFF99" />
<HeaderStyle BackColor="#999999" Font-Bold="True" ForeColor="#003399" HorizontalAlign="Center" />
<AlternatingRowStyle BorderColor="Black" BorderWidth="3px" BorderStyle="Ridge" />
</asp:GridView>
</td>
<td style="height: 282px"> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td style="height: 37px"> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td valign="top">
<asp:SqlDataSource runat="server" id="sd1" ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT * FROM [PendingRecords]" DeleteCommand="DELETE FROM [PendingRecords] WHERE [ID] = ?" InsertCommand="INSERT INTO [PendingRecords] ([Username], [Password], [FirstName], [LastName], [MiddleName], [Address], [Gender], [ContactNumber], [PlateNumber], [Color], [Brand], [LiscensedNumber]) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" UpdateCommand="UPDATE [PendingRecords] SET [Username] = ?, [Password] = ?, [FirstName] = ?, [LastName] = ?, [MiddleName] = ?, [Address] = ?, [Gender] = ?, [ContactNumber] = ?, [PlateNumber] = ?, [Color] = ?, [Brand] = ?, [LiscensedNumber] = ? WHERE [ID] = ?">
<DeleteParameters>
<asp:parameter Name="ID" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asp:parameter Name="Username" Type="String" />
<asp:parameter Name="Password" Type="String" />
<asp:parameter Name="FirstName" Type="String" />
<asp:parameter Name="LastName" Type="String" />
<asp:parameter Name="MiddleName" Type="String" />
<asp:parameter Name="Address" Type="String" />
<asp:parameter Name="Gender" Type="String" />
<asp:parameter Name="ContactNumber" Type="String" />
<asp:parameter Name="PlateNumber" Type="String" />
<asp:parameter Name="Color" Type="String" />
<asp:parameter Name="Brand" Type="String" />
<asp:parameter Name="LiscensedNumber" Type="String" />
<asp:parameter Name="ID" Type="Int32" />
</UpdateParameters>
<InsertParameters>
<asp:parameter Name="Username" Type="String" />
<asp:parameter Name="Password" Type="String" />
<asp:parameter Name="FirstName" Type="String" />
<asp:parameter Name="LastName" Type="String" />
<asp:parameter Name="MiddleName" Type="String" />
<asp:parameter Name="Address" Type="String" />
<asp:parameter Name="Gender" Type="String" />
<asp:parameter Name="ContactNumber" Type="String" />
<asp:parameter Name="PlateNumber" Type="String" />
<asp:parameter Name="Color" Type="String" />
<asp:parameter Name="Brand" Type="String" />
<asp:parameter Name="LiscensedNumber" Type="String" />
</InsertParameters>
</asp:SqlDataSource>
</td>
<td> </td>
<td style="height: 33px"> </td>
</tr>
<tr>
<td style="width: 32px"> </td>
<td style="width: 8px"> </td>
<td style="width: 87px"> </td>
<td style="width: 542px"> </td>
<td style="width: 447px"> </td>
<td style="height: 83px; width: 34px;"> </td>
</tr>
</table>
Please modify your markup and code to include the OnRowDeleting
event.
<asp:GridView OnPageIndexChanging="PendingRecordsGridview_PageIndexChanging" ID="PendingRecordsGridview" runat="server" AutoGenerateColumns="False" DataKeyNames="ID" OnRowcommand="PendingRecordsGridview_RowCommand" DataSourceID="sd1" BorderStyle="Ridge" BackColor="White" BorderColor="Black" BorderWidth="3px" CellPadding="4" Width="1070px" PageSize="2" AllowPaging="True">
<RowStyle ForeColor="#003399" HorizontalAlign="Center" OnRowDeleting="PendingRecordsGridview_RowDeleting"/>
On the code behind add this method.
public void PendingRecordsGridview_RowDeleting (Object sender, GridViewDeleteEventArgs e)
{
}
这篇关于GridView的'PendingRecordsGridview'触发了事件RowDeleting,它没有被处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!