我把购物车的信息以DataTable的形式放在Session里,然后与GridView绑定就可以查看购物车内容了。但是如果我想在GridView里增加Select、Edit、Delete等按钮(以及相应处理程序)应该怎么办?
在正常情况下,我用一个ObjectDataSource同GridView绑定,可以在设计状态增加各种按钮,但是现在的GridView在开发环境里空荡荡的怎么设置呢?
谢谢各位的帮助!
------解决方案--------------------------------------------------------
GridView自带了编辑功能
如<asp:TemplateField HeaderText="操作" ItemStyle-HorizontalAlign="Center" ShowHeader="False">
<HeaderStyle Width="20%"></HeaderStyle>
<EditItemTemplate>
<asp:LinkButton ID="LinkButton5" runat="server" CausesValidation="True" CommandName="update">保存</asp:LinkButton>
<asp:LinkButton ID="LinkButton4" runat="server" CausesValidation="False" CommandName="cancel">取消</asp:LinkButton>
</EditItemTemplate>
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CommandName="edit" CausesValidation="false" OnClientClick="return confirm('确认要编辑吗?');">编辑</asp:LinkButton>
<asp:LinkButton ID="LinkButton2" runat="server" CommandName="delete" CausesValidation="False" OnClientClick="return confirm('确认要删除吗?');">删除</asp:LinkButton>
<asp:LinkButton ID="LinkButton3" runat="server" CommandName="Select" CausesValidation="False" Visible="false" >选取</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
protected void gv_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
BindData();
}
protected void gv_RowEditing(object sender, GridViewEditEventArgs e)
{
this.gv.EditIndex = e.NewEditIndex;
BindData();
}
protected void gv_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
this.gv.EditIndex = e.RowIndex;
int id = int.Parse(this.gv.DataKeys[e.RowIndex].Value.ToString());
this.gv.EditIndex = -1;
BindData();
}
protected void gv_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
gv.EditIndex = -1;
BindData();
}
------解决方案--------------------------------------------------------
帮楼上顶。。。
------解决方案--------------------------------------------------------
帮定~