这是CS代码:
private void BindDataList()
{
string  sqlADD="select * from RevGoodsAddr where userid=" + LoginUsers.GetSessionUserID().ToString();
ds=UserTools.UserDataSet(sqlADD);
DL_SendAddr.DataSource=ds;
DL_SendAddr.DataBind();
} private void DL_SendAddr_EditCommand(object source, System.Web.UI.WebControls.DataListCommandEventArgs e)
{
this.DL_SendAddr.EditItemIndex=e.Item.ItemIndex;
BindDataList();
} private void DL_SendAddr_CancelCommand(object source, System.Web.UI.WebControls.DataListCommandEventArgs e)
{
DL_SendAddr.EditItemIndex=-1;
BindDataList();
} private void DL_SendAddr_DeleteCommand(object source, System.Web.UI.WebControls.DataListCommandEventArgs e)
{
string sqlStr="Delete From RevGoodsAddr where id="+DL_SendAddr.DataKeys[e.Item.ItemIndex];
UserTools.ExecuteSQL(sqlStr);
DL_SendAddr.EditItemIndex=-1;
BindDataList();
} public void DL_SendAddr_UpdateCommand(object source, System.Web.UI.WebControls.DataListCommandEventArgs e)
{
TextBox TBRealName;
TextBox TBZip;
TextBox TBTel;
TextBox TBCeilPhone;
TextBox TBClearAddr;
TBRealName=(TextBox)(e.Item.FindControl("TB_RealName"));
TBZip=(TextBox)e.Item.FindControl("TB_Zip");
TBTel=(TextBox)e.Item.FindControl("TB_Tel");
TBCeilPhone=(TextBox)e.Item.FindControl("TB_CeilPhone");
TBClearAddr=(TextBox)e.Item.FindControl("TB_ClearAddr");
string sqlStr="Update RevGoodsAddr set RealName='"+TBRealName.Text+
"',zip='"+TBZip.Text+"',tel='"+TBTel.Text+
"',CeilPhone='"+TBCeilPhone.Text+"',ClearAddr='"+TBClearAddr.Text+
"' where id="+DL_SendAddr.DataKeys[e.Item.ItemIndex];
UserTools.ExecuteSQL(sqlStr);
DL_SendAddr.EditItemIndex=-1;
BindDataList();
}

解决方案 »

  1.   

    跟踪的时候DL_SendAddr_UpdateCommand跟踪不到!
      

  2.   

    我有LOAD事件的代码
    private void InitializeComponent()
    {    
    this.DL_SendAddr.CancelCommand += new System.Web.UI.WebControls.DataListCommandEventHandler(this.DL_SendAddr_CancelCommand);
    this.DL_SendAddr.EditCommand += new System.Web.UI.WebControls.DataListCommandEventHandler(this.DL_SendAddr_EditCommand);
    this.DL_SendAddr.UpdateCommand += new System.Web.UI.WebControls.DataListCommandEventHandler(this.DL_SendAddr_UpdateCommand);
    this.DL_SendAddr.DeleteCommand += new System.Web.UI.WebControls.DataListCommandEventHandler(this.DL_SendAddr_DeleteCommand);
    this.DL_SendAddr.SelectedIndexChanged += new System.EventHandler(this.DL_SendAddr_SelectedIndexChanged);
    this.Load += new System.EventHandler(this.Page_Load); }
      

  3.   

    <asp:linkbutton  ..... CommandName="Delete" ...>
    <asp:linkbutton  ..... CommandName="Edit" ...>
    <asp:linkbutton  ..... CommandName="Update" ...>
    <asp:linkbutton  ..... CommandName="Select" ...>
    注意CommandName的首字母大写,
    另外可以用ItemCommand事件跟踪一下,或者直接用ItemCommand事件处理
    DataGrid1_ItemCommand(..)
    {
       if(e.CommandName == "update")
       {
       }
       else if(e.CommandName == "delete")
       {
       }
    }