Click here to Skip to main content
15,892,768 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a datalist that has a textbox in the edit item template and i can set the text propery of the txtbox but whenever I run my app and type something in the textbox and run my updatye command the textbox text is empty or null.

here is my updatye command

C#
protected void Update(object source, DataListCommandEventArgs e)
{
    if (!IsPostBack)
    {
        DataList1.DataBind();

        SqlCommand cmd1 = new SqlCommand("Update install_Add_Test set installName = '" + ((TextBox)e.Item.FindControl("editInstallName")).Text.ToString() + "' where id = '1'", cs);
        cs.Open();
        cmd1.ExecuteNonQuery();
        //Response.Write(editInstallName);


        cs.Close();
        //Response.Redirect("DatalistTest.aspx");
        //DataList1.DataBind();

        DataList1.EditItemIndex = -1;

    }


I didn't want to put all of my code in this post but if I need to I can. It just seems like the textbox.txt value should change whenever I type something in it and hit my update link button. Please let me know if more info is needed. Thanks in Advance.
Posted
Comments
Richard C Bishop 27-Mar-13 13:53pm    
Is there a particular reason you are using !IsPostBack? If the page does not post back or use asyncronous post backs, the code-behind will never get executed. When debugging does the if statement ever get satisfied in order to run the code inside it?
Dustin Prevatt 27-Mar-13 14:21pm    
I've removed that and still the same outcome. i'm trying to set the txtbox txt value to the value in the db so that the txt box will populate that when the user hits the edit button but then when they change the value in the textbox i want it to then change the txtbox.txt value so i can use the new value for my update statement to the DB.
Prasad Khandekar 27-Mar-13 22:32pm    
Hello Dustin,

DataList1.DataBind() probably will reset the value of the textbox and you will not get the value typed in by the user.

1 solution

Hello Dustin ,
Try to remove DataList1.DataBind();
And try again
 
Share this answer
 

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