GridView加ObjectDataSource做删除事件(ObjectDataSourceStatusEventHandler 委托)
<asp:GridView ID="GVAllMemo" runat="server" AutoGenerateColumns="False" CellPadding="4" GridLines="None" Width="80%" AllowPaging="True" AllowSorting="True" DataSourceID="ObjectDataSource1" ForeColor="#333333" Font-Size="9pt" DataKeyNames="ID" >
<FooterStyle BackColor="#5D7B9D" ForeColor="White" Font-Bold="True" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<Columns>
<asp:BoundField DataField="EndDate" HeaderText="提醒时间" DataFormatString="{0:yyyy年M月dd日}" HtmlEncode="False"/>
<asp:TemplateField HeaderText="具体事务">
<ItemTemplate>
<a href="MemoShow.aspx?Date=<%# Eval("EndDate") %>" class="f12_black" > <%# Eval("event") %></a>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="StartDate" HeaderText="添加时间" DataFormatString="{0:yyyy年M月dd日}" HtmlEncode="False" />
<asp:TemplateField HeaderText="完成状况">
<ItemTemplate>
<%# Convert.ToInt32(Eval("Flag")) == 0 ? "<img src='../images/ico_no.gif' alt='未完成'/>" : "<img src='../images/ico_ok.gif' alt='完成'/>"%>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="编辑">
<ItemTemplate>
<a href="MemoEdit.aspx?ID=<%# Eval("id") %>" class="f12_black" > 编辑</a>
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowDeleteButton="True" />
</Columns>
<EditRowStyle BackColor="#999999" />
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<PagerSettings FirstPageText="首页" LastPageText="末页" NextPageText="下一页" PreviousPageText="上一页" />
</asp:GridView>
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectMethod="AllMemo"
TypeName="JL.CRM.BLL.BllMemo" DeleteMethod="DelMemo" OnDeleting="GridView1_RowDeleting">
<SelectParameters>
<asp:SessionParameter Name="KFnum" SessionField="KFnum" Type="Int32" />
</SelectParameters>
<deleteparameters>
<asp:parameter name="ID" type="Int32" />
</deleteparameters>
</asp:ObjectDataSource>
<FooterStyle BackColor="#5D7B9D" ForeColor="White" Font-Bold="True" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<Columns>
<asp:BoundField DataField="EndDate" HeaderText="提醒时间" DataFormatString="{0:yyyy年M月dd日}" HtmlEncode="False"/>
<asp:TemplateField HeaderText="具体事务">
<ItemTemplate>
<a href="MemoShow.aspx?Date=<%# Eval("EndDate") %>" class="f12_black" > <%# Eval("event") %></a>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="StartDate" HeaderText="添加时间" DataFormatString="{0:yyyy年M月dd日}" HtmlEncode="False" />
<asp:TemplateField HeaderText="完成状况">
<ItemTemplate>
<%# Convert.ToInt32(Eval("Flag")) == 0 ? "<img src='../images/ico_no.gif' alt='未完成'/>" : "<img src='../images/ico_ok.gif' alt='完成'/>"%>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="编辑">
<ItemTemplate>
<a href="MemoEdit.aspx?ID=<%# Eval("id") %>" class="f12_black" > 编辑</a>
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowDeleteButton="True" />
</Columns>
<EditRowStyle BackColor="#999999" />
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<PagerSettings FirstPageText="首页" LastPageText="末页" NextPageText="下一页" PreviousPageText="上一页" />
</asp:GridView>
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectMethod="AllMemo"
TypeName="JL.CRM.BLL.BllMemo" DeleteMethod="DelMemo" OnDeleting="GridView1_RowDeleting">
<SelectParameters>
<asp:SessionParameter Name="KFnum" SessionField="KFnum" Type="Int32" />
</SelectParameters>
<deleteparameters>
<asp:parameter name="ID" type="Int32" />
</deleteparameters>
</asp:ObjectDataSource>
C#代码段
protected void GridView1_RowDeleting(object source, ObjectDataSourceMethodEventArgs e)
{
BllMemo DelMemo = new BllMemo();
IDictionary paramsFromPage = e.InputParameters;
if (DelMemo.DelMemo(Int32.Parse(paramsFromPage["ID"].ToString())))
{
JavaScript.Alert("删除成功!", this.Page);
GVAllMemo.DataBind();
}
else
{
JavaScript.Alert("删除失败!", this.Page);
}
}
{
BllMemo DelMemo = new BllMemo();
IDictionary paramsFromPage = e.InputParameters;
if (DelMemo.DelMemo(Int32.Parse(paramsFromPage["ID"].ToString())))
{
JavaScript.Alert("删除成功!", this.Page);
GVAllMemo.DataBind();
}
else
{
JavaScript.Alert("删除失败!", this.Page);
}
}