繁体   English   中英

索引更改不起作用 asp.net 中的下拉列表

[英]On index change not working drop down list in asp.net

我试图在我的 ASP.NET 项目中添加选定的索引更改方法。 它以前工作得很好,但突然间我在项目中使用的所有下拉列表没有得到回发。 并且在选定的索引更改现在不起作用。

<asp:DropDownList ID="selectDropDownList" runat="server" AutoPostBack="True" CssClass="form-control" Width="100%"
                OnSelectedIndexChanged="selectDropDownList_SelectedIndexChanged" EnableViewState="true">
                 
</asp:DropDownList>
log4net.ILog log  = log4net.LogManager.GetLogger(typeof(ClassNAME))
    protected void selectDropDownList_SelectedIndexChanged(object sender, EventArgs e)
        {
            log.Info("select change in department ");
            ShowData();
        }

我的 web.config 文件是

<?xml version="1.0" encoding="utf-8"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  https://go.microsoft.com/fwlink/?LinkId=169433
  -->
<configuration>
    <configSections>
        <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
    </configSections>
    <connectionStrings>
        <add name="FinalConnectionString" connectionString="Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=D:\UAS_MSU\UAS_MSU\App_Data\Database.mdf;Integrated Security=True" providerName="System.Data.SqlClient" />
    </connectionStrings>
    <system.web>
        <compilation debug="true" targetFramework="4.7.2" />
        <httpRuntime targetFramework="4.7.2" />
        <pages maintainScrollPositionOnPostBack="true" enableEventValidation="false" >
            <namespaces>
                <add namespace="System.Web.Optimization" />
            </namespaces>
            <controls>
                <add assembly="Microsoft.AspNet.Web.Optimization.WebForms" namespace="Microsoft.AspNet.Web.Optimization.WebForms" tagPrefix="webopt" />
                <add tagPrefix="ajaxToolkit" assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" />
            </controls>
        </pages>
    </system.web>
    <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
            <dependentAssembly>
                <assemblyIdentity name="Antlr3.Runtime" publicKeyToken="eb42632606e9261f" />
                <bindingRedirect oldVersion="0.0.0.0-3.5.0.2" newVersion="3.5.0.2" />
            </dependentAssembly>
            <dependentAssembly>
                <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" />
                <bindingRedirect oldVersion="0.0.0.0-12.0.0.0" newVersion="12.0.0.0" />
            </dependentAssembly>
            <dependentAssembly>
                <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" />
                <bindingRedirect oldVersion="0.0.0.0-1.6.5135.21930" newVersion="1.6.5135.21930" />
            </dependentAssembly>
            <dependentAssembly>
                <assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
                <bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
            </dependentAssembly>
            <dependentAssembly>
                <assemblyIdentity name="log4net" publicKeyToken="669e0ddf0bb1aa2a" culture="neutral" />
                <bindingRedirect oldVersion="0.0.0.0-2.0.12.0" newVersion="2.0.12.0" />
            </dependentAssembly>
        </assemblyBinding>
    </runtime>
    <system.codedom>
        <compilers>
            <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:1659;1699;1701" />
            <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+" />
        </compilers>
    </system.codedom>
    <log4net>
        <root>
            <level value="ALL" />
            <appender-ref ref="RollingLogFileAppender" />
        </root>
        <appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
            <file value="C:\\logs\\log.log" />
            <appendToFile value="true" />
            <rollingStyle value="Size" />
            <maxSizeRollBackups value="10" />
            <maximumFileSize value="10000KB" />
            <staticLogFileName value="true" />
            <layout type="log4net.Layout.PatternLayout">
                <conversionPattern value="%-5p %d %5rms %-22.22c{1} %-18.18M - %m%n" />
            </layout>
        </appender>
    </log4net>
</configuration>

我尝试在 web.config 中进行一些更改,但没有成功...更改我所做的<pages maintainScrollPositionOnPostBack="true" enableEventValidation="false" ><pages >

我怀疑这是某些 web 配置更改的结果。

你能创建一个新的测试 web 页面吗? 在下拉列表中拖放。

说使用这个标记:

现在在设计器中 - 显示属性表。

在此处输入图像描述

现在,在属性表中 - select 事件,然后双击:

在此处输入图像描述

现在,只要说:

protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
Debug.Print(DropDownList1.SelectedValue);    // get value of selected item (text)
Debug.Print(DropDownList1.Text);             // same as value
Debug.Print(DropDownList1.SelectedIndex);    // get index (row) of selected item
}

当然,现在您只需输入 debug.print 部分 - 应该为您正确生成代码存根。

事实上,显示现有下拉列表的属性表,然后双击该属性表上的 selectedIndexChanged 事件。 听起来事件代码存根已取消挂钩或未附加到给定控件。

那么,测试 web 页面是否有效? 先试试那个。

如果测试页面有效,则 go 回到您现有的 - 尝试按照上述重建事件代码子。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM