【问题标题】:Dropdown event not firing下拉事件未触发
【发布时间】:2011-12-05 03:53:21
【问题描述】:

我在网格的 HeaderTemplate 中有一个 DropdownLIst 我已经在此下拉列表的 selectedINDexChanged 事件上编写了一些服务器端代码 但是这个事件永远不会触发。 我还启用了下拉的 ViewState 和 Page 为 true Ant ide 一定是什么问题

【问题讨论】:

  • 您是否将下拉菜单的自动回发设置为 true?
  • 向我们展示您创建 DropDownList 以及将其绑定到其 DataSource 的相关代码(或者您已添加项目)。

标签: asp.net gridview drop-down-menu aspxgridview


【解决方案1】:

我已经在我的环境中解决了这个问题....请查看下面的代码..

这是我在 aspx 页面中的gridview

 <asp:GridView ID="grvGrid" runat="server" AllowPaging="True"   
            AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="CustomerID" OnRowDataBound="grvGrid_RowDataBound">  
            <Columns>  
                <asp:BoundField DataField="CustomerID" HeaderText="CustomerID" ReadOnly="True"   
                    SortExpression="CustomerID" />  
                <asp:BoundField DataField="CompanyName" HeaderText="CompanyName"   
                    SortExpression="CompanyName" />  
               <asp:TemplateField>
                    <HeaderTemplate>
                        <%--<asp:Label ID="lblMon1" runat="server"></asp:Label>--%>
                        <asp:DropDownList id="ddlMon" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddlMon_SelecdtedIndexChanges">
                            <asp:ListItem Text="1" Value="1" Selected="True">1</asp:ListItem>
                            <asp:ListItem Text="2" Value="2">2</asp:ListItem>
                            <asp:ListItem Text="3" Value="3">3</asp:ListItem>
                        </asp:DropDownList>
                    </HeaderTemplate>
                    <ItemTemplate>
                        <asp:Label ID="lblblbl" runat="server"></asp:Label>
                    </ItemTemplate>
               </asp:TemplateField>
            </Columns>  
        </asp:GridView> 

在页面加载事件中获取网格视图绑定

protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            GetTable();
            grvGrid.DataSource = dstable;
            grvGrid.DataBind();
        }
    }

找到 DropDown 控件并绑定它的事件

protected void grvGrid_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (Page.IsPostBack)
        {
            if (e.Row.RowType == DataControlRowType.Header)
            {
                DropDownList ddlmon = e.Row.FindControl("ddlMon") as DropDownList;
                ddlmon.SelectedIndexChanged += new EventHandler(ddlMon_SelecdtedIndexChanges);
            }
        }
    }

DropDown SelectedIndex 更改事件

protected void ddlMon_SelecdtedIndexChanges(object sender, EventArgs e)
    {
        // Your Code paste here
    }

【讨论】:

  • 你得到你的答案是不是!!!!如果事情是对的,你应该接受你的答案!!!!
【解决方案2】:

这里可能的问题是您的DropDownList 可能没有设置属性

AutoPostBack="true" try add this to your `DropDownList`

【讨论】:

    猜你喜欢
    • 2013-11-25
    • 1970-01-01
    • 1970-01-01
    • 2021-09-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多