gridview编辑列(不使用控件绑定数据源)
需要如下代码:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:TemplateField HeaderText="类别ID"><ItemTemplate><%#
Eval("ID") %></ItemTemplate></asp:TemplateField>
<asp:TemplateField HeaderText="类别名"><ItemTemplate><%#
Eval("CaName") %></ItemTemplate></asp:TemplateField>
</Columns>
</asp:GridView>
在gridview标签中,设置AutoGenerateColumns="False",最主要的就是<%# Eval("ID") %>,gridview中“类别ID”这一列的值,取表中ID这一列的值
表的级联删除
二级删除触发器:
CREATE TRIGGER deleteCategory ON category
INSTEAD OF DELETE
AS
DECLARE @id int;
SELECT @id=ID from deleted;
DELETE FROM Subject
WHERE CaID=@id;
DELETE FROM Category
WHERE ID=@id;
三级删除触发器:
create trigger delCategory on Category
instead of delete
as
declare @caid int
select @caid=ID from deleted
--删除评论
delete from Restore where SubjID in (select ID from Subject where CaID=@caid) --in是关键,是包含关系,所有CaID=@caid的主题的ID都会被选出。
--删除主题
delete from Subject where CaID=@caid
--删除类别
delete from Category where ID=@caid
添加数据集:
添加数据集,添加tableadapter,添加查询语句,然后可直接调用adapter的各种方法。
例如:
DataSet1TableAdapters.CategoryTableAdapter dtdCa = new DataSet1TableAdapters.CategoryTableAdapter();
DataSet1.CategoryDataTable dtblCa = new DataSet1.CategoryDataTable();
dtdCa.Fill(dtblCa);
GridView1.DataSource = dtblCa;
GridView1.DataBind();