You need to declare the string variable outside of if condition.
protected void ImageButton2_Click1(object sender, ImageClickEventArgs e)
{
string price = string.Empty;
if (TextBox1.Text != "0")
{
price = RadioButton2.Checked ? TextBox1.Text : "";
}
else {
price = TextBox1.Text = "";
}
int data1 = Convert.ToInt32(Request.QueryString["id"].ToString());
SqlCommand _cmd = new SqlCommand("editproduct1", _cn);
_cmd.CommandType = CommandType.StoredProcedure;
_cn.Open();
_cmd.Parameters.AddWithValue("@ID", data1);
_cmd.Parameters.AddWithValue("@Name", txtname.Text); _cmd.Parameters.AddWithValue("@Description", elm1.Text);
_cmd.Parameters.AddWithValue("@Price", price);
_cmd.ExecuteNonQuery();
Session["Message"] = true;
Response.Redirect(Request.Url.AbsoluteUri);
_cn.Close();
}
Now price variable will be available for complete Button Click event.