日期:2014-05-18  浏览次数:20403 次

各位帮忙,快!!
<Asp:DataGrid     id= "mygride "   OnDeleteCommand= "dgdelete "   runat=server   Width= "234px "   >
   
        <Columns>
        <Asp:ButtonColumn   Text= "删除 "   CommandName= "delete ">
        </Asp:ButtonColumn>
        </Columns>
       
        </Asp:DataGrid>
设计代码
public   void   dgdelete(object   send,DataGridCommandEventArgs   e)
{
        SqlCommand   com   =   new   SqlCommand( "delete   form   car   where   Col001=@cc ");
        com.Parameters.Add(new   SqlParameter( "@cc ",   SqlDbType.Char,   255));
        //com.Parameters[ "@cc "]   =mygride.DataKeys[int.Parse(e.Item.ItemIndex)];

com.Parameters[ "@cc "].Value   =   mygride.DataKeys[(int)e.Item.ItemIndex];
       
        //this.con.Open();
        //try
        //{
        //         com.ExecuteNonQuery();
        //         Response.Write( "成功删除!! ");

        //}
        //catch   (SqlException)
        //{
        //         Response.Write( "无法删除!! ");

        //}

        //this.con.Close();
        //bindgrid();

}
        public   void   bindgrid()
        {
                DataSet   ds   =   new   DataSet();
                SqlCommand   com   =   new   SqlCommand( "select   *   from   car ",this.con);
                SqlDataAdapter   da=new   SqlDataAdapter();
                da.SelectCommand   =   com;
                da.Fill(ds,   "car ");
                this.mygride.DataSource   =   ds.Tables[ "car "].DefaultView;
                this.mygride.DataBind();


        }
com.Parameters[ "@cc "].Value   =   mygride.DataKeys[(int)e.Item.ItemIndex];
解悉这句话的具体含义!!
是给参数cc赋的什么值呀!!
多谢!!


------解决方案--------------------
mygride 的 指定第ItemIndex行 datakeys的值
------解决方案--------------------
如 SqlCommand com = new SqlCommand( "delete form car where Col001=@cc ");
com.Parameters[ "@cc "] = 123;

则SQL语句为
delete form car where Col001=123

------解决方案--------------------
SqlCommand com = new SqlCommand( "delete form car where Col001=@cc ");
com.Parameters[ "@cc "].Value = m