注册 登录
编程论坛 ASP.NET技术论坛

删除按钮不起作用

baozishi 发布于 2007-12-18 18:31, 752 次点击
我用的是在Datagrid中删除..但点击它不起作用..
事件代码是:
public void stugrid_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{     Response.Write("lll");

    if(stugrid.Items.Count==1)
        {
        if(stugrid.CurrentPageIndex!=0)
            {
            stugrid.CurrentPageIndex = stugrid.CurrentPageIndex-1;
            }
        }
    stugrid.DataKeyField="time";
    string id = this.stugrid.DataKeys[e.Item.ItemIndex].ToString(); //定义数据健,取得ID
    SqlConnection con = new SqlConnection("server=(local);user id=sa;password=sql;database=datac;");
    SqlCommand com = new SqlCommand("delete from datainfo where time=@time",con);
    com.Parameters.Add ("@time",SqlDbType.DateTime ,10);
    com.Parameters ["@time"].Value =id;
    con.Open();
    com.ExecuteNonQuery();
    BindGrid();
}


在DATAGRID中:
<asp:datagrid id="stugrid" runat="server" AutoGenerateColumns="false" OnEditCommand="stugrid_Edit"

OnUpdateCommand="stugrid_Update" OnCancelCommand="stugrid_Cancel" OnButtonCommand="stugrid_DeleteCommand" >
列控件在上面的DATAGRID中,代码是:
<asp:ButtonColumn
    ButtonType="LinkButton"
    CommandName="Delete"
    HeaderText="删除"
    Text="删除"
    Visible="True"/>
3 回复
#2
baozishi2007-12-18 18:32
我定义的是当前系统时间为主键..
它的属性是:DateTime
#3
bygg2007-12-19 10:17
你设个断点跟踪一下,看一下 delete from datainfo where time=@time是什么东东....
#4
huwei10242007-12-19 11:42
提示: 作者被禁止或删除 内容自动屏蔽,只有管理员可见
1