【问题标题】:Event that fires when user clicks on the "New" button of an ASP.Net DetailsView当用户单击 ASP.Net DetailsView 的“新建”按钮时触发的事件
【发布时间】:2013-01-04 17:24:58
【问题描述】:

在 ASP.Net VB.Net 代码隐藏文件中,您能否告诉我,当用户在 DetailsView 显示空白项时单击 DetailsView 的“新建”按钮时,我可以使用哪些事件触发来捕获?比如 DropDownLists、TextBoxes 等?

我需要使用此事件处理程序在从变量获取的 DropDownList 中预选一个值。

【问题讨论】:

    标签: asp.net vb.net event-handling code-behind html-select


    【解决方案1】:

    试试 ItemCommand 事件。这是如何使用它。我只知道 C# ,但我想你已经掌握了窍门。

    后面的代码:

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

    标记:

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

    【讨论】:

    • 感谢您的回复。我会尝试那个活动,让你知道我成功了。
    • 我发现单击“插入”按钮时有一个很好的选择。你知道哪个更适合“新建”按钮吗?
    • 使用 ItemCommand 是要走的路。谢谢你。我尝试使用以下代码使 DropDownList 选择值,但列表仍未显示数据。你能告诉我额外需要的编码来让它工作吗? Case "New" Dim drpValue As DropDownList drpValue = DetailsView.FindControl("DropDownListClass") drpValue.SelectedValue = StrListValueToSelect
    猜你喜欢
    • 1970-01-01
    • 2010-10-21
    • 2011-12-02
    • 1970-01-01
    • 2020-05-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-05
    相关资源
    最近更新 更多