Click here to Skip to main content
12,999,157 members (42,700 online)
Rate this:
Please Sign up or sign in to vote.
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

    protected void Update(object source, DataListCommandEventArgs e)
        if (!IsPostBack)
            SqlCommand cmd1 = new SqlCommand("Update install_Add_Test set installName = '" + ((TextBox)e.Item.FindControl("editInstallName")).Text.ToString() + "' where id = '1'", cs);

            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 7:43am
richcb 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

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

Solution 1

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

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170622.1 | Last Updated 28 Mar 2013
Copyright © CodeProject, 1999-2017
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