For example, we want to take a date type of data, in the database column name is updated, the value is 2008/06/01. But like the June 01, 2008 show, we can write bind ("updated", "{0:yyyy mm month DD Day}"), and so does eval.
All 2 can read the values in the data and display them. When we use the edit update operation, bind can automatically update the modified values to the database and display the modified values. But the eval only gets the wrong picture, and the new data is not updated into the database.
From this point of view, the difference between the bind method and the Eval method is that the bind method is OK in the 2 aspects of reading and updating data, but the Eval method can only read the display data. So, when we choose the Bind method and the Eval method, there must be contention, and when the data definitely needs to be updated, we should use BIND, just display the data, and we can use the Eval method without any action.
In the update operation we can operate in the Gridview1_rowupdating event, as shown in the following example:
Copy Code code as follows:
protected void Gridview1_rowupdating (object sender, Gridviewupdateeventargs e)
{
Update Row GridViewRow
GridViewRow row = this. Gridview1.rows[e.rowindex];
Find an updated control
DropDownList present = (DropDownList) row. FindControl ("Ddlpresent");
TextBox price = (textbox) row. FindControl ("Txtprice");
TextBox updated = (textbox) row. FindControl ("txtupdated");
Update
E.newvalues["Present"] = present. SelectedValue;
e.newvalues[' price ' = Price. Text;
e.newvalues["updated"] = updated. Text;
}
protected void Gridview1_rowupdating (object sender, Gridviewupdateeventargs e)
{
Update Row GridViewRow
GridViewRow row = this. Gridview1.rows[e.rowindex];
Find an updated control
DropDownList present = (DropDownList) row. FindControl ("Ddlpresent");
TextBox price = (textbox) row. FindControl ("Txtprice");
TextBox updated = (textbox) row. FindControl ("txtupdated");
Update
E.newvalues["Present"] = present. SelectedValue;
e.newvalues[' price ' = Price. Text;
e.newvalues["updated"] = updated. Text;
}
If we can fully understand the bind method and the Eval method, there is no need to write to the above, it can be done automatically. The above method is used in addition to the more complex operations, which is also a skill to use.