Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET
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
 
    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 27-Mar-13 8:43am
Comments
richcb at 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 at 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 at 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

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Hello Dustin ,
Try to remove DataList1.DataBind();
And try again
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 8,149
1 Sergey Alexandrovich Kryukov 7,287
2 DamithSL 5,614
3 Manas Bhardwaj 4,986
4 Maciej Los 4,910


Advertise | Privacy | Mobile
Web03 | 2.8.1411023.1 | Last Updated 28 Mar 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100