Default value of a TextBox being columns in the database

Go To


I'm not sure if this has been answered before, I looked for about a half an hour with no luck, so if it has been, sorry.

I am trying to have all TextBox on the page load with default values that are in the database, so the user can edit each value and save with one button without emptying out each text box.

I have added a form view and put the text boxes inside the >ItemTemplate> tags, so that I can add text='<%#Eval("DataBaseColumn")%>' as default values but the problem is, it doesn't have the values on page load.

Is there a way that I should be doing this with viewstate?

Any help would be great. Thanks in advance

2012-04-04 05:37
by adam baum


If I understand correctly, you're trying to set form data from a database. You've already halfway there - you've initialized and set up the view. Next thing to do is to fill the data that the view is going to use. That is done in some method in web form code-behind like Page_Load using the following:

ViewState["SomeKey"] = SomeValue;

You then can get this data using the "SomeKey" key.

2012-04-04 05:49
by Dmitry Reznik
Thanks for the quick answer.

Yes that is correct, it is an edit profile page and the issue that I am having is, when the page loads the text boxes are empty and the form uses one button to submit the changes to the profile database, so if I was to change my first name, I would have to fill in every text box before submitting the changes, if not, the form would remove all existing data in all fields except the firstname that I just put in.

So are you saying that I would declare the ViewState as a variable on page load and the make the - adam baum 2012-04-04 19:38


please make your gridview in edit mode

protected void Gridview1_ItemCreated(object sender, EventArgs e)
        FormView fv = sender as FormView ;
        if (fv.CurrentMode == FormViewMode.Edit)


You will get your Default value loaded their... Cheers!!

2012-04-04 05:52
by Sunil Chavan
Thanks for the response - adam baum 2012-04-04 19:42