我在aspx頁面中使用帶有sqldatasource的detailsview。 我想對一些字段進行一些預處理和後處理 - 基本上是將html列表轉換爲換行符分隔的列表以進行編輯並返回到html以存儲在數據庫中。如何修改DetailsView Databound事件中的數據
在ItemUpdating後處理是很容易的,但在數據綁定前處理是凌亂...
protected void DetailsView1_DataBound(object sender, EventArgs e)
{
if (DetailsView1.Rows.Count > 2)
{
string s =((DataRowView)DetailsView1.DataItem).Row.ItemArray[2].ToString();
TextBox box1 = (TextBox) DetailsView1.FindControl("textbox1");
if (box1 != null)
{
box1.Text = preprocess(s);
}
}
}
其
string s=((DataRowView)DetailsView1.DataItem).Row.ItemArray[2].ToString();
這打亂了我的脆弱。我確定我錯過了一件事(不止一件事),顯而易見!
我猜我希望做一些更喜歡我的ItemUpdating ...
e.NewValues["threeline"] = postprocess(e.NewValues["threeline"].ToString());