2
Answers

asp.net update from textbox not working

I am trying to update a field from a Datalist but the value from Textbox is not changing. On Update command, the value is not changed

<div class="row no-gutters">
    <asp:TextBox ID="txtLocatieEdit" class="form-control form-control-sm bg-white text-center"
        TextMode="MultiLine" Rows="1"
        Style="font-size: 11px; resize: none;"
        Text='<%#Eval("Locatie")%>'
        runat="server" />
</div>

and code behind

if (e.CommandName == "Update")
{
    TextBox Locatie = (TextBox)e.Item.FindControl("txtLocatieEdit");

    using (SqlConnection conn = new SqlConnection(connString))
    {
        string sqlQuery = "UPDATE tblDefRap SET Locatie = @Locatie WHERE IdDR = @IdDR";
        using (SqlCommand cmd = new SqlCommand(sqlQuery, conn))
        {
            cmd.CommandType = CommandType.Text;

            cmd.Parameters.AddWithValue("@IdDR", iddr);
            cmd.Parameters.AddWithValue("@Locatie", Locatie.Text);

            conn.Open();

            int result = cmd.ExecuteNonQuery();
            if (result > 0)
            {
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Record Inserted Successfully')", true);
            }
            DataList2.EditItemIndex = -1;
            conn.Close();
        }
        GetWorkOrder();
    }
}

The value entered in the database is the same as the one trying to change and I don't understand why

Answers (2)