This is a migrated thread and some comments may be shown as answers.

How to call UpdateCommand from external button click?

1 Answer 124 Views
Button
This is a migrated thread and some comments may be shown as answers.
Jason
Top achievements
Rank 1
Jason asked on 21 Sep 2015, 07:55 PM

 

I have an external button that needs to call my UpdateCommand event, but I am not sure how to do it.  Here is what I have so far:

protected void RadGrid2_UpdateCommand(object sender, GridCommandEventArgs e)
{
     String connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["KBConnectionString"].ConnectionString;
     try
     {
          string answerid = e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["AnswerID"].ToString();
 
          using (SqlConnection conn = new SqlConnection(connectionString))
          {
               conn.Open();
               SqlCommand cmd = new SqlCommand("UPDATE Answers SET Answer_Name = @prmAnswer_Name, Answer = @prmAnswer, TimeAdded = CURRENT_TIMESTAMP WHERE AnswerID = " + answerid, conn);
               cmd.Parameters.Add(new SqlParameter("@prmAnswer_Name", RadTextBox1.Text));
               cmd.Parameters.Add(new SqlParameter("@prmAnswer", RadEditor.Text));
               cmd.ExecuteNonQuery();
               conn.Close();
          }
     }
     catch (Exception)
     {
          RadScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('There was a problem finding the ID, please contact support.')", true);
     }
}
Button click:

protected void RadButton2_Click(object sender, EventArgs e)
{           
     //CommandEventArgs cea = new CommandEventArgs(RadTextBox1.Text, RadEditor.Text);
     //GridCommandEventArgs args = new GridCommandEventArgs(null, "Edit", cea);
     //RadGrid2_UpdateCommand(sender, args);
}
 How do I call the UpdateCommand event from the external button click?

1 Answer, 1 is accepted

Sort by
0
Konstantin Dikov
Telerik team
answered on 24 Sep 2015, 10:30 AM
Hello Jason,

Can you please refer to the answer in other forum post, where you have asked the same question:
On a side note, for better tracking purposes and for all sides convenience, please try to avoid opening multiple threads with duplicated questions. Thank you for your understanding.


Regards,
Konstantin Dikov
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Button
Asked by
Jason
Top achievements
Rank 1
Answers by
Konstantin Dikov
Telerik team
Share this question
or