的SelectedIndexChanged

时间:2011-11-24 17:20:00

标签: c# javascript asp.net

问题:

SelectedIndexchanged不会触发。我尝试用断点进行调查,但它甚至没有参加此次活动。 我通过双击组合框来制作活动。但它没有帮助。 请指教。

以下是代码:

    protected void nav_dd_parent_edit_SelectedIndexChanged(object sender, EventArgs e)
            {

            }   
    <td width="55%" class="style1" height="20px">
                                    <asp:DropDownList ID="nav_dd_parent_edit" runat="server" 
                                        DataSourceID="sp_GetNavParents_Edit" DataTextField="Name" 
                                        DataValueField="NavItemId" Height="24px" ReadOnly="FALSE" Width="375px" 
                                        onselectedindexchanged="nav_dd_parent_edit_SelectedIndexChanged">
                                    </asp:DropDownList>
                                </td>

protected void Page_Load(object sender, EventArgs e)
        {

            if (!Page.IsPostBack)
            {
                //Page.MaintainScrollPositionOnPostBack = true;
                //SiteMaster.g_solution = "Couche-Tard - QV";
                //SiteMaster.g_solution_id = 27;
                nav_dd_parent.DataBind();
                if (SiteMaster.g_solution != null && SiteMaster.g_solution != "")
                {
                    nav_literal.Text = "Solution: " + SiteMaster.g_solution;
                    nav_hidden_SoltnId.Value = SiteMaster.g_solution_id.ToString();
                }
                else
                {
                    nav_literal.Text = "Please select a solution first from the 'Solution Template' Tab.";
                    panel_top.Visible = false;
                }
            }

3 个答案:

答案 0 :(得分:6)

您没有看到您的断点被点击,因为当选择更改时,下拉列表不会回发。

AutoPostBack设置为true,您应该全部设置。

答案 1 :(得分:1)

我注意到你的DropDownList Id是“nav_dd_parent_edit”,但你的Page_Load正在“nav_dd_parent”上调用Databind方法 - 这可能是问题的一部分吗?

无论如何,我做了DropDownList的简化版本工作正常 - 也许它可能会有所帮助。

<table>
    <tr>
        <td width="55%" class="style1" height="20px">
            <asp:DropDownList  
                ID="nav_dd_parent" 
                runat="server" 
                DataTextField="Name" 
                DataValueField="NavItemId" 
                Height="24px" 
                ReadOnly="FALSE" 
                Width="375px" 
                onselectedindexchanged="nav_dd_parent_edit_SelectedIndexChanged" 
                AutoPostBack="true">
             </asp:DropDownList>
         </td>
    </tr>
</table>


protected void Page_Load(object sender, EventArgs e)
{
    if (!Page.IsPostBack)
    {                
        nav_dd_parent.Items.Add(new ListItem("Item 1", "1"));
        nav_dd_parent.Items.Add(new ListItem("Item 2", "2"));
        nav_dd_parent.Items.Add(new ListItem("Item 3", "3"));
    }
}

protected void nav_dd_parent_edit_SelectedIndexChanged(object sender, EventArgs e)
{
    int codeGetsHere = 0;
}   

答案 2 :(得分:0)

请注意以下几点注意事项:

一个。将'AutoPostBack'设置为true:

    <asp:DropDownList ID="nav_dd_parent_edit" runat="server"  AutoPostBack="true"
        DataSourceID="sp_GetNavParents_Edit" DataTextField="Name" 
        DataValueField="NavItemId"
        onselectedindexchanged="nav_dd_parent_edit_SelectedIndexChanged">
    </asp:DropDownList>

湾始终绑定不回发时间:

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