根据按钮的不同的CommandArgument处理每个按钮的单击事件的代码

 

根据" 

如何在面板中创建动态内容的经典代码

"中的按钮btn所写的删除事件的代码


private void OnDeletePlace(Object sender, CommandEventArgs e)
        
{
            
// e.CommandArgument receives the LapseID to delete
            SqlConnection con;
            SqlCommand cmd;

            
// Connect and execute the query
            con = new SqlConnection("data source=(local)\\NetSdk;initial catalog=FriendsData;user id=sa");
            cmd 
= new SqlCommand("DELETE FROM TimeLapse WHERE LapseID='" + e.CommandArgument.ToString() + "'", con);
            con.Open();

            
try
            
{
                cmd.ExecuteNonQuery();
            }

            
catch 
            
{
                
// Just pass the exception up
                throw;
            }

            
finally
            
{
                con.Close();
            }

//删除之后还需重新绑定数据并显示
            LoadDataSet();
            InitPlaces();
        }

posted @ 2005-06-11 12:55  虚空境界  Views(484)  Comments(0)    收藏  举报