菜鸟问题,DeleteMethod是啥……? 10
这是我一个页面的部分代码:<asp:GridViewID="GridView1"runat="server"Width="794px"AutoGenerateColumn...
这是我一个页面的部分代码:
<asp:GridView ID="GridView1" runat="server" Width="794px" AutoGenerateColumns="False" DataSourceID="ObjectDataSource1" AllowPaging="True" OnRowDeleted="GridView1_RowDeleted" OnRowCommand="GridView1_RowCommand" OnRowDeleting="GridView1_RowDeleting" OnRowDataBound="GridView1_RowDataBound">
...................
<asp:TemplateField HeaderText="删除">
<ItemTemplate>
<asp:Button ID="btnDel" runat="server" CommandArgument='<%# Eval("Id") %>' CommandName="Delete" Text="删除" />
</ItemTemplate>
</asp:TemplateField>
.............
这是页面后台的部分代码:
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Delete")
{
int categoryID = Convert.ToInt32(e.CommandArgument);
this.Label4.Text = categoryID.ToString();
}
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Button btn = (Button)e.Row.FindControl("btnDel");
btn.Attributes.Add("onclick", "javascript:return " + "confirm('是否要删除该记录? " +
DataBinder.Eval(e.Row.DataItem, "Id") + "')");
}
}
运行后当我按【删除】的时候有弹出对话框,但是按确定后页面就显示:
除非指定 DeleteMethod,否则 ObjectDataSource“ObjectDataSource1”不支持删除。
我不太明白DeleteMethod是啥
还有,我应该把代码怎么写完整才能实现删除记录的功能?
麻烦指教,谢谢 展开
<asp:GridView ID="GridView1" runat="server" Width="794px" AutoGenerateColumns="False" DataSourceID="ObjectDataSource1" AllowPaging="True" OnRowDeleted="GridView1_RowDeleted" OnRowCommand="GridView1_RowCommand" OnRowDeleting="GridView1_RowDeleting" OnRowDataBound="GridView1_RowDataBound">
...................
<asp:TemplateField HeaderText="删除">
<ItemTemplate>
<asp:Button ID="btnDel" runat="server" CommandArgument='<%# Eval("Id") %>' CommandName="Delete" Text="删除" />
</ItemTemplate>
</asp:TemplateField>
.............
这是页面后台的部分代码:
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Delete")
{
int categoryID = Convert.ToInt32(e.CommandArgument);
this.Label4.Text = categoryID.ToString();
}
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Button btn = (Button)e.Row.FindControl("btnDel");
btn.Attributes.Add("onclick", "javascript:return " + "confirm('是否要删除该记录? " +
DataBinder.Eval(e.Row.DataItem, "Id") + "')");
}
}
运行后当我按【删除】的时候有弹出对话框,但是按确定后页面就显示:
除非指定 DeleteMethod,否则 ObjectDataSource“ObjectDataSource1”不支持删除。
我不太明白DeleteMethod是啥
还有,我应该把代码怎么写完整才能实现删除记录的功能?
麻烦指教,谢谢 展开
2个回答
展开全部
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
SelectMethod="GetAllMessage" TypeName="MessageBLL.MessageManager"
DeleteMethod="DeleteMessage"
>
<DeleteParameters>
<asp:Parameter Name="id" Type="Int32" />
</DeleteParameters>
</asp:ObjectDataSource>
就是数据源里面需要这个:
DeleteMethod="DeleteMessage" (DeleteMessage:是你需要删除的方法绑定到数据源里面)
SelectMethod="GetAllMessage" TypeName="MessageBLL.MessageManager"
DeleteMethod="DeleteMessage"
>
<DeleteParameters>
<asp:Parameter Name="id" Type="Int32" />
</DeleteParameters>
</asp:ObjectDataSource>
就是数据源里面需要这个:
DeleteMethod="DeleteMessage" (DeleteMessage:是你需要删除的方法绑定到数据源里面)
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询