Since you cannot call the Bind
"method" from within another public method in your markup (like you can do with Eval
), it looks like you are stuck doing a normal "Bind" in the EditItemTemplate
:
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server"
Text='<%# Bind("Time") %>'>
</asp:TextBox>
</EditItemTemplate>
Note: you need to do a Bind
, because that will make it show up in your ItemUpdating event later, to save it to the database
Then update it for display purposes as soon as the DetailsView is databound (make sure it's also in Edit Mode):
protected void yourDetailsView_DataBound(object sender, EventArgs e)
{
if (yourDetailsView.CurrentMode == DetailsViewMode.Edit)
{
TextBox timeTextBox = (TextBox)yourDetailsView.FindControl("TextBox1");
timeTextBox.Text = TimeSpanToString(timeTextBox.Text);
}
}
Then, you can handle the ItemUpdating
event, and manipulate the value of "Time" prior to saving it to the database:
protected void yourDetailsView_ItemUpdating(object sender, DetailsViewUpdateEventArgs e)
{
String newTime = e.NewValues["Time"].ToString();
e.NewValues["Time"] = StringToTimespan(newTime);
}
Notice you can extract the user-entered values from the DetailsViewUpdateEventArgs.NewValues
collection