I'm using a detailsview with an sqldatasource in the aspx page. I'm trying to do some pre and post processing on some of the fields - basically to convert a html list to a newline separated list for editing and back to html to store in the database.
The post-processing in ItemUpdating is easy enough but the pre-processing in DataBound is messy...
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);
}
}
}
Its the fragility of
string s=((DataRowView)DetailsView1.DataItem).Row.ItemArray[2].ToString();
that upsets me. I'm sure I am missing something (more than one thing) obvious!
I guess I was hoping to do something more like my ItemUpdating...
e.NewValues["threeline"] = postprocess(e.NewValues["threeline"].ToString());