Search code examples
asp.netvb.netevent-handlingcode-behindhtml-select

Event that fires when user clicks on the "New" button of an ASP.Net DetailsView


In an ASP.Net VB.Net code-behind file, can you tell me what event fires that I can use to trap when the user clicks on the "New" button of a DetailsView at the time the DetailsView shows blank items such as DropDownLists, TextBoxes etc?

I need use this event handler to pre-select a value in a DropDownList obtained from a variable.


Solution

  • Try the ItemCommand event. This is how to use it. I only know C# , but I think you get the hang of it.

    Code behind:

    protected void DetailsView_ItemCommand(object sender, DetailsViewCommandEventArgs e)
    {
        if (e.CommandName == "New")
        {
            // Your code here
        }
    }
    

    Markup:

    <asp:DetailsView ID="DetailsView" runat="server" OnItemCommand="DetailsView_ItemCommand" ...