GridView自己带的删除的问题???
错误是这样的:
GridView1”激发了未处理的事件“RowDeleting”。 数据源已经生成删除语句;
-------------------------------
源代码:
<asp:GridView ID= "GridView1 " runat= "server " AutoGenerateColumns= "False " BackColor= "White "
BorderColor= "#0099FF " BorderStyle= "Solid " BorderWidth= "1px " CellPadding= "3 " DataSourceID= "SqlDataSource1 "
GridLines= "Horizontal " Width= "800px " DataKeyNames= "ProductID ">
<FooterStyle BackColor= "#B5C7DE " ForeColor= "#4A3C8C " />
<Columns>
<asp:BoundField DataField= "title " HeaderText= "产品标题 " SortExpression= "title ">
<ItemStyle HorizontalAlign= "Center " Width= "100px " />
<ControlStyle CssClass= "prode_edit1 " />
</asp:BoundField>
<asp:TemplateField HeaderText= "简单介绍 ">
<ItemTemplate>
<asp:Label ID= "Label3 " runat= "server " CssClass= "gv_pro1 " Text= ' <%# Eval( "EasyIntro ") %> '> </asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText= "修改内容 ">
<ItemStyle Width= "80px " HorizontalAlign= "Center " />
<ItemTemplate>
<a href= 'modifyPro.aspx?id= <%# Eval( "ProductID ") %> ' class= "lj1 "> <asp:Label ID= "Label1 " runat= "server " Text= "修改内容 "> </asp:Label> </a>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText= "预览内容 ">
<ItemStyle Width= "80px " HorizontalAlign= "Center " />
<ItemTemplate>
<a href= 'prePro.aspx?id= <%# Eval( "ProductID ") %> ' class= "lj1 "> <asp:Label ID= "Label4 " runat= "server " Text= "预览内容 "> </asp:Label> </a>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText= "建立时间 ">
<ItemTemplate>
<asp:Label ID= "lblTime " runat= "server " Text= ' <%# db.shorttime(Eval( "btime ").ToString()) %> '> </asp:Label>
</ItemTemplate>
<ItemStyle Width= "100px " HorizontalAlign= "Center " />
</asp:TemplateField>
<asp:TemplateField HeaderText= "删除 ">
<ItemTemplate>
<asp:ImageButton ID= "ImageButton2 " runat= "server " CommandName= "Delete " />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<RowStyle BackColor= "#FFE0C0 " ForeColor= "Black " BorderStyle= "None " />
<SelectedRowStyle BackColor= "#738A9C " Font-Bold= "True " ForeColor= "#F7F7F7 " />
<PagerStyle BackColor= "#E7E7FF " ForeColor= "#4A3C8C " HorizontalAlign= "Right " />
<HeaderStyle Font-Bold= "True " ForeColor= "#000040 " BorderStyle= "None " CssClass= "head1 " />
<AlternatingRowStyle BackColor= "#F7F7F7 " />
</asp:GridView>
[解决办法]
没有关联事件
<asp:GridView ID= "GridView1 " AutoGenerateColumns= "false " runat= "server " OnRowDeleting= "GridView1_RowDeleting " >
protected void GridView1_RowDeleting(object sender, GridViewEditEventArgs e)
{
//...
}
[解决办法]
看你用什么數據源。。。如果有通過數據源控件如:objectdatasource。是不需要寫事件。
如果是用databind。那就要。
[解决办法]
<asp:GridView ID= "gvBaseProductKind " runat= "server " AutoGenerateColumns= "False " Width= "100% " OnRowDataBound= "gvBaseProductKind_RowDataBound " DataKeyNames= "ProductKindID " OnRowCancelingEdit= "gvBaseProductKind_RowCancelingEdit " OnRowDeleting= "gvBaseProductKind_RowDeleting " OnRowEditing= "gvBaseProductKind_RowEditing " OnRowUpdating= "gvBaseProductKind_RowUpdating ">
点击以后都是有事件的 你看一下 GridView 的事件 点击进去写