我在 aspx 页面中使用带有 sqldatasource 的详细信息视图。我正在尝试对某些字段进行一些预处理和后处理 - 基本上是将 html 列表转换为换行符分隔的列表以进行编辑并返回 html 以存储在数据库中。
ItemUpdating 中的后处理很简单,但 DataBound 中的预处理很混乱......
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());