i want to convert a label to textbox and the value of the label should read from databse. On Label click as it converts to textbox, then i can enter any value into the text box. Then on TextBox_TextChanged it updates the value in the database and converts to label with the updated value
On page load the value of the machine Label lblname.Text is always empty, so we need to edit the label to input a value to store to the database. But the problem is that if the lblname value is empty, i mean if the value of lblname.Text is null, the lblname is not editable so you cant edit the label. What i need is for the lblname to be editable even if the value is null.
Please help
My Code
public partial class Default14 : System.Web.UI.Page
{
SqlCommand cmd1 = new SqlCommand();
SqlCommand cmd = new SqlCommand();
SqlConnection dbConn = new SqlConnection();
SqlConnection dbConn1 = new SqlConnection();
SqlConnection dbConn2 = new SqlConnection();
SqlDataReader dr, dr2, dr1, dr3;
string selectSQL, updateSQL, selectSQL1;
protected void Page_Load(object sender, EventArgs e)
{
lblName.Text="";
}
protected void TextBox1_TextChanged(object sender, EventArgs e)
{
string name = Request.Form["txtName"];
lblName.Text = name;
SqlConnection dbConn = new SqlConnection();
SqlCommand cmd = new SqlCommand();
string updateSQL;
updateSQL = "update job set machine ='" + name + "' where id='21' ";
dbConn.ConnectionString = WebConfigurationManager.ConnectionStrings["DB_SCH"].ConnectionString;
cmd.Connection = dbConn;
cmd.CommandText = updateSQL;
cmd.CommandType = CommandType.Text;
try
{
dbConn.Open();
int updated = cmd.ExecuteNonQuery();
if (updated == 1)
{
// Response.Redirect("changepassw.aspx");
}
else
{
// Label101.Text = "Process not Completed";
}
dbConn.Close();
}
catch (Exception err)
{
Response.Write(err.ToString());
}
finally
{
dbConn.Close();
}
}
}
Please help