自定义GridView的删除操作的问题
问题描述:
GridView绑定一个SqlDataSource,SqlDataSource的特殊点在于:SelectCommand和DeleteCommand都是自定义的存储过程,并且都有参数.
SelectCommand语句的执行没有问题,GridView中能正常显示数据,在单击GridView的删除按钮时需要截住GridView的GridView_RowDeleting,在此处理一下key和Value,以让其适应SQLDataSource的Delete命令(也就是适应我自定义的删除存储过程需要的参数),然后继续进行删除操作.谁能告诉我如何处理GridView_RowDeleting中这些key和Value以让其适应SQLDataSource的Delete命令?
备注:要实现这种操作,其实也可以拦截SQLDataSource的RowDeleting,但是在这个事件种很难获取某些输入值,所以我想在GridView_RowDeleting种解决问题.
[解决办法]
sqldatasource我没这样搞过,帮你顶一下
[解决办法]
It is easier to use an ObjectDatasource and strong typed dataset.
[解决办法]
可以的
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Delete ")
[解决办法]
up
[解决办法]
gridview & objectdatasource的关联使用:
005的blog
ref:http://www.cnblogs.com/eddie005/archive/2006/08/28/488507.html
[解决办法]
<asp:GridView ID= "GridView1 " runat= "server " OnPageIndexChanging= "GridView1_PageIndexChanging "
OnSorting= "GridView1_Sorting " AutoGenerateColumns= "False " AllowPaging= "True " AllowSorting= "True "
Width= "100% " CellPadding= "4 " ForeColor= "#333333 " GridLines= "None " OnRowDeleting= "GridView1_RowDeleting "
DataKeyNames= "公告编号,公告名称 ">
<Columns>
<asp:TemplateField ShowHeader= "False ">
<ItemTemplate>
<asp:ImageButton ID= "delete " runat= "server " CommandName= "delete " OnClientClick= "return confirm( '确认要删除吗? '); " ImageAlign= "Middle " ImageUrl= "\OA\Images\delete.gif "> </asp:ImageButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
____________
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
string 公告编号 = GridView1.DataKeys[e.RowIndex].Values[0].ToString();
SqlDataReader r;
SQLHelper sqlHelp = new SQLHelper();
string SqlStr = "delete from Announce where 公告编号= " + 公告编号;
sqlHelp.ExecSQL(SqlStr);
GridView1.EditIndex = -1;
BindGrid();
}
[解决办法]
应该就是楼上的吧/。
看看都象。。支持下。。