Hey, I have been checking some other questions related to this topic, and have done what they recommend, but none of them worked.
I am having problems setting a field (a template field - bounded) in a detailsview, when edditing the row. I have tried several events: ModeChanged, ModeChanging, ItemUpdating, ItemCreated (in edit mode) but none of them works.
What I need to do is simply to set a today's date into a field whenever the row is changed (an audit field), and I also want to see it on the screen
If I try to do this in the itemcreated event (edit mode) ... the control cannot be found.
If I do it in the itemupdating, the control is found, but the value is not set, and even if I update the row, the date field is not set.
I also use the same code when inserting a row, and here it works, I don´t quite understand why it works in the itemcreated event (insert mode), but not when edditing.
The code is this:
TextBox
txt;
if (DVEmpresa.CurrentMode == DetailsViewMode.Edit)
{
txt =
this.DVEmpresa.FindControl("txtFechModi") as TextBox;
txt.Text =
DateTime.Now.ToString();
}
and the fields is:
<
asp:TemplateField HeaderText="Fecha Última Modificación" SortExpression="fecultmod">
<EditItemTemplate>
<asp:TextBox ID="txtFechModi" runat="server" Text='<%# Bind("fecultmod") %>' Font-Names="Calibri" Font-Size="12pt" Height="22px" Width="248px"></asp:TextBox>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="txtFechModi" runat="server" Text='<%# Bind("fecultmod") %>' Font-Names="Calibri" Font-Size="12pt" Width="248px"></asp:TextBox>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="txtFechModi" runat="server" Text='<%# Bind("fecultmod") %>' Font-Names="Calibri" Font-Size="12pt" Height="22px" Width="248px"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
I really appreciate some help to solve this.
TIA
Maria