.NET Framework Developer Center > Using Forums Forums > Off-Topic Posts (Do Not Post Here) > How to set a field in a Detailsview in edit mode
Ask a questionAsk a question
 

QuestionHow to set a field in a Detailsview in edit mode

  • Friday, November 06, 2009 4:39 PMmebv Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    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 &#218;ltima Modificaci&#243;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

    • Moved byeryangMSFTMonday, November 09, 2009 3:10 AM (From:.NET Base Class Library)
    •  

All Replies

  • Monday, November 09, 2009 3:09 AMeryangMSFTUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi,
    Thanks for your post, but it is tend to get quicker and better response/support in http://forums.asp.net where asp experts live in.

    Thanks,

    Eric


    Please remember to mark helpful replies as answers and unmark them if they provide no help.