DataGrid能够正确显示,只是删除按钮无效
我写的删除代码如下。。。[控件的事件里也添加好了]
public void DataGrid_Delete(Object sender,DataGridCommandEventArgs E)
{
Response.Write("<script>alert('收到删除消息')</script>");
//从文件Web.config中读取连接字符串
string strconn= ConfigurationSettings.AppSettings["dsn"];
//连接本地计算机的数据库
SqlConnection cn= new SqlConnection (strconn);
cn.Open ();
SqlCommand cm=new SqlCommand ("usersdelete",cn);//读取存储过程
cm.CommandType =CommandType.StoredProcedure ;
cm.Parameters .Add ("@UserID",SqlDbType.VarChar );
//从DateGrid中取得更新内容
Response.Write("<script>alert('" + "你选择的用户的ID号为:"+ E.Item.Cells[0].Text + "')</script>");
cm.Parameters ["@UserID"].Value =E.Item.Cells [0].Text .ToString ();
Response.Write("<script>alert('" + "删除了" + cm.ExecuteNonQuery().ToString() + "行数据" + "')</script>");//该提示框显示共删除了0行数据
DataGrid1.EditItemIndex =-1;
BindGrid();
Response.Write("<script>alert('" + "已刷新页面数据" + "')</script>");
}
结果是前台和后台数据库都没有更新。
usersdelete存储过程如下:
CREATE PROCEDURE [UsersDelete]
(@UserID [varchar])
AS DELETE [03075411].[dbo].[Users]
WHERE
( [UserID] = @UserID)
GO
HTML的DataGrid代码如下。。:
<asp:DataGrid id="DataGrid1" style="Z-INDEX: 101; LEFT: 16px; POSITION: absolute; TOP: 88px" runat="server"
Width="553px" AllowPaging="True" BorderColor="#CC9966" BorderStyle="None" BorderWidth="1px"
BackColor="White" CellPadding="4" AutoGenerateColumns="False" AllowCustomPaging="True">
<FooterStyle ForeColor="#330099" BackColor="#FFFFCC"></FooterStyle>
<SelectedItemStyle Font-Bold="True" ForeColor="#663399" BackColor="#FFCC66"></SelectedItemStyle>
<ItemStyle ForeColor="#330099" BackColor="White"></ItemStyle>
<HeaderStyle Font-Bold="True" ForeColor="#FFFFCC" BackColor="#990000"></HeaderStyle>
<Columns>
<asp:BoundColumn DataField="UserID" ReadOnly="True" HeaderText="员工编号"></asp:BoundColumn>
<asp:BoundColumn DataField="UserName" ReadOnly="True" HeaderText="员工姓名"></asp:BoundColumn>
<asp:BoundColumn DataField="UserPole" HeaderText="用户类型"></asp:BoundColumn>
<asp:BoundColumn DataField="UserTel" ReadOnly="True" HeaderText="电话"></asp:BoundColumn>
<asp:BoundColumn DataField="UserAddress" HeaderText="员工住址"></asp:BoundColumn>
<asp:HyperLinkColumn DataNavigateUrlField="UserID" DataNavigateUrlFormatString="yuangongxiugai.aspx?UserID={0}"
DataTextField="UserID" HeaderText="修改" DataTextFormatString="详单"></asp:HyperLinkColumn>
<asp:ButtonColumn Text="删除" CommandName="Delete"></asp:ButtonColumn>
</Columns>
<PagerStyle NextPageText="下一页" PrevPageText="上一页" HorizontalAlign="Center" ForeColor="#330099"
BackColor="#FFFFCC"></PagerStyle>
</asp:DataGrid>
到底哪里出问题了呢|||||||||||
还有一星期就毕业答辩了||||||白头发都出来了||||