Click here to Skip to main content
14,732,983 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,
i am deleting a single row using linkbutton click....i need a code for linkbutton click using stored procedure
Posted
Comments
Prerak Patel 13-Sep-11 4:25am
   
Any efforts?

First of All You have to bind your link button command Argument property
that's the value which will be pass to your store procedure so your record will be deleted


 protected void lnkDelete_Click(object sender, EventArgs e)
 {
     LinkButton lnk = (LinkButton)sender;
     SqlCommand cmd = new SqlCommand();
     if (SqlCon != null && SqlCon.State != ConnectionState.Open)
     {
         SqlCon.Open();
     }
     cmd.Connection = SqlCon;
     cmd.CommandText = "YOUR STORE PROCEDURE NAME";
     cmd.CommandType = CommandType.StoredProcedure;
     cmd.Parameters.AddWithValue("YOUR PARAMETER NAME",lnk.CommandArgument.ToString());
     cmd.ExecuteNonQuery();

}



you can do this using this method also
for this you have to set command name and command argument property of link button

protected void GridView1_RowCommand(object sender,
                         GridViewCommandEventArgs e)
{
  if (e.CommandName == "Delete";)
  {
    int categoryID = Convert.ToInt32(e.CommandArgument);
     SqlCommand cmd = new SqlCommand();
     if (SqlCon != null && SqlCon.State != ConnectionState.Open)
     {
         SqlCon.Open();
     }
     cmd.Connection = SqlCon;
     cmd.CommandText = "YOUR STORE PROCEDURE NAME";
     cmd.CommandType = CommandType.StoredProcedure;
     cmd.Parameters.AddWithValue("YOUR PARAMETER NAME",categoryID);
     cmd.ExecuteNonQuery();

  }
}
   
v3
CultureInfo defaultCultureInfo = CultureInfo.CurrentCulture;
DayOfWeek firstDay = defaultCultureInfo.DateTimeFormat.FirstDayOfWeek;
if (firstDay != DayOfWeek.Monday)
{
firstDay = DayOfWeek.Monday;
}
DateTime firstDayInWeek = DateTime.Now.Date;
while (firstDayInWeek.DayOfWeek != firstDay)
{
firstDayInWeek = firstDayInWeek.AddDays(-1);
}
   
Comments
Prerak Patel 14-Sep-11 1:26am
   
What is this?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900