.net C # postback overwrites associated text field

I have a gridview whose contents are provided by accessdatasource. The data displayed depends on the dropdown that the postback event has.

  • Page loading
  • The user selects an item from the drop-down list.
  • reloads pages with new data in gridview

So far so good

Then I added a text box to the grid view (no, I can’t use the standard "edit" link) The text box is in itemtemplate

This text box contains editable data that the user can update and send back to the server by clicking the update button.

The problem is that I change the selection in the gridview update drop-down list as it should, but the text fields retain the old value, even if they are associated with <% # Bind ("vr_total")%>

I can only assume that this is caused by postback data and that the data is overwritten after the binding occurs. (otherwise the binding will overwrite the old unwanted data)

Can someone explain how I can change this behavior.

viewstate set to false

I'm new to .net and C #

DC

Further development.

If I replace the <asp: text <input type = "text" value = "<% # Eval (" vr_total ")%>" ... text field, the grid works exactly as expected.

, gridview , , , ( postback ), .

+3
2

, ControlState, . , , , , .

, , - Page_Load OnPreRender.

:

private void Page_Load(object sender, System.EventArgs e)
{
  grid.DataSource = whatever;
}

// your dropdown event occurs between these two events

protected override void OnPreRender(EventArgs e)
{
   grid.DataBind();
}

ASP.NET ViewState, http://msdn.microsoft.com/en-us/library/ms972976.aspx

+3

, Page.DataBind,

override void OnLoad(){
    if(this.IsPostBack == false){
        this.DataBind();
    }
}

- , , . .

, onChange , , Gridview, .

void OnDropDownChange(EventArgs args){
    gridView.DataBind();
}

, - Databinding, . http://support.microsoft.com/kb/307860 .

0

Source: https://habr.com/ru/post/1720629/


All Articles