★五一到了,送51分★,顺便帮我看看这个好久没有解决的问题!
我是菜鸟一个,可能很简单,别笑我啊!
在使用gridview控件时,启用了 "启用删除 ",数据源里面也生成了删除啊,为什么点击 "删除 "后一点作用都不起呢???
代码如下:
---------------------------------------------
<asp:GridView ID= "GridView1 " runat= "server " AutoGenerateColumns= "False " BackColor= "White "
BorderColor= "#E7E7FF " BorderStyle= "None " BorderWidth= "1px " CellPadding= "3 " DataSourceID= "SqlDataSource1 "
GridLines= "Horizontal " Width= "600px ">
<FooterStyle BackColor= "#B5C7DE " ForeColor= "#4A3C8C " />
<Columns>
<asp:BoundField DataField= "Title " HeaderText= "包含的栏目 " SortExpression= "Title ">
<ItemStyle HorizontalAlign= "Center " />
</asp:BoundField>
<asp:TemplateField HeaderText= "修改 ">
<ItemStyle HorizontalAlign= "Center " />
<ItemTemplate>
<a href= 'edit.aspx?source=AboutUs&id= <%# Eval( "USID ") %> ' class= "lj1 "> <asp:Label ID= "lblEdit " runat= "server " Text= ' <%# db.book(Eval( "USID ").ToString()) %> '> </asp:Label> </a>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText= "预览 ">
<ItemStyle HorizontalAlign= "Center " />
<ItemTemplate>
<a href= 'PreView.aspx?source=AboutUs&id= <%# Eval( "USID ") %> ' class= "lj1 "> <asp:Label ID= "lblPreview " runat= "server " Text= "预览 " Enabled= ' <%# IsShow.showUs(Eval( "USID ").ToString()) %> '> </asp:Label> </a>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField= "DateTime " HeaderText= "最后修改的时间 " SortExpression= "DateTime ">
<ItemStyle HorizontalAlign= "Center " />
</asp:BoundField>
<asp:CommandField HeaderText= "删除 " ShowDeleteButton= "True " ShowHeader= "True ">
<ItemStyle HorizontalAlign= "Center " />
</asp:CommandField>
</Columns>
<RowStyle BackColor= "#E7E7FF " ForeColor= "Black " Height= "25px " />
<SelectedRowStyle BackColor= "#738A9C " Font-Bold= "True " ForeColor= "#F7F7F7 " />
<PagerStyle BackColor= "#E7E7FF " ForeColor= "#4A3C8C " HorizontalAlign= "Right " />
<HeaderStyle Font-Bold= "True " ForeColor= "#F7F7F7 " CssClass= "head1 " />
<AlternatingRowStyle BackColor= "#F7F7F7 " ForeColor= "Black " Height= "25px " />
</asp:GridView>
<asp:SqlDataSource ID= "SqlDataSource1 " runat= "server " ConnectionString= " <%$ ConnectionStrings:kunxiang %> "
SelectCommand= "SELECT [USID], [Title], [DateTime] FROM [AboutUs] ORDER BY [DateTime] DESC " DeleteCommand= "DELETE FROM [AboutUs] WHERE [USID] = @USID " InsertCommand= "INSERT INTO [AboutUs] ([Title], [DateTime]) VALUES (@Title, @DateTime) " UpdateCommand= "UPDATE [AboutUs] SET [Title] = @Title, [DateTime] = @DateTime WHERE [USID] = @USID ">
<DeleteParameters>
<asp:Parameter Name= "USID " Type= "Int32 " />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name= "Title " Type= "String " />
<asp:Parameter Name= "DateTime " Type= "DateTime " />
<asp:Parameter Name= "USID " Type= "Int32 " />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name= "Title " Type= "String " />
<asp:Parameter Name= "DateTime " Type= "DateTime " />
</InsertParameters>
</asp:SqlDataSource>
-------------------------
好象之前有一次成功过,不知道为什么多数时候不行;还有如果自己建了Template列,拖如个linkbutton,将其commandname设为delete,好象也可以啊
拜托
顺便祝大家五一快乐!!!!!!!!!!!
[解决办法]
在RowDeleted 事件中捕获异常Exceotion信息,并根据异常进行处理。
异常是设计时必须考虑的。不处理异常,不算是正式的程序。
[解决办法]
DataKeyNames= "USID "