Dropdownlist邦定数据后,为何不触发SelectedIndexChanged事件。我是直接邦定的而不是手工将数据添加到Dropdownlist中的,如果手工添加进去可以触发,请各位帮我找一下原因。

解决方案 »

  1.   

    将DropDownList的属性: AutoPostBack设置为: true
      

  2.   

    private void drpupfile_SelectedIndexChanged(object sender, System.EventArgs e)
    {
    string url = Doc.SystemFramework.AppManager.GetInstance().NewBoardAttachUrl;//取web端地址
    IWSInvoke invoke = null;
    DALService dal = AppManager.GetInstance().DALService;
    invoke = new NewsDAL(dal);
    string newid=this.drpupfile.SelectedValue;
    DataTable dt = invoke.GetData(MethodName.GetData,NewsMapping.NewsID+"="+this.newsID).Tables[0];
    DataRow row = dt.Rows[0];
    string name=this.drpupfile.SelectedItem.Text;
    string data = Convert.ToDateTime(row[NewsMapping.CreatedDate].ToString()).ToString("yyyy");
    string filename=Path.Combine(data,this.newsID.ToString());
    filename=Path.Combine(filename,name);
    filename=Path.Combine(url,filename);
    this.Response.Redirect(filename,false);
    }
    private void InitializeComponent()
    {    
    this.txtContent.TextChanged += new System.EventHandler(this.txtContent_TextChanged);
    this.drpupfile.SelectedIndexChanged += new System.EventHandler(this.drpupfile_SelectedIndexChanged);
    this.Load += new System.EventHandler(this.Page_Load); }
      

  3.   

    if (!this.IsPostBack) {
                //Dropdownlis数据帮定代码
     }
      

  4.   

    private void Page_Load(object sender, System.EventArgs e)
    {
    Response.Expires = 0;
    if (!this.IsPostBack)
    {
    this.newsID = int.Parse(this.Request.QueryString["NewsID"]);
                    this.GetData(newsID);
    this.getupfile(newsID);
    }
    } private void GetData(int newsID)
    {
    try
    {
    IWSInvoke invoke = null;
    DALService dal = AppManager.GetInstance().DALService;
    invoke = new NewsDAL(dal);
    DataTable dt = invoke.GetData(MethodName.GetData,NewsMapping.NewsID+"="+newsID).Tables[0];
    DataRow row = dt.Rows[0];
    this.lbRTitle.Text = row[NewsMapping.NewsTitle].ToString();
    this.txtContent.Text = row[NewsMapping.Content].ToString();
    this.lbRCreatedBy.Text = row[NewsMapping.CreatedBy].ToString();
    this.lbRCreatedDate.Text = Convert.ToDateTime(row[NewsMapping.CreatedDate].ToString()).ToString("yyyy-MM-dd hh:mm:ss");
    }
    catch
    {
       
    }
      

  5.   

    这是邦定数据
    private void getupfile(int newsID)
    {
    try
    {
    IWSInvoke invoke = null;
    DALService dal = AppManager.GetInstance().DALService;
    invoke = new NewsDAL(dal);
    DataTable dt = invoke.GetData(MethodName.News.GetAttachment,newsID).Tables[0];
    foreach(DataRow row in dt.Rows)
    {
    // System.Web.UI.WebControls.Label upfile=new Label();
    //// this.drpupfile.Items.Add(row[AttachmentMapping.FileName].ToString());
    // this.drpupfile.Items.Add(new ListItem(row[AttachmentMapping.FileName].ToString(),row[AttachmentMapping.NewsID].ToString()));
      

    }

    this.drpupfile.DataTextField=AttachmentMapping.FileName;
    this.drpupfile.DataValueField=AttachmentMapping.NewsID;
    this.drpupfile.DataSource=dt;
    this.drpupfile.DataBind();


    }
    catch
    {
    }
      

  6.   

    是这样的:Dropdownlist的属性AutoPostBack设置为false即可
      

  7.   

    掉事件我也碰到过,检查下你除了这些代码部分之外,事件委托正常吗?
    另外有可能是PostBack的问题或你的VS.NET IDE出了问题。在你的ddl上点右键-属性-在SelectedIndexChanged事件上点右键-重置,然后双击进入写好代码并检查上面的事件委托是否正确。
      

  8.   

    看看网页中(Html)有没有其他地方设置影响了调用
      

  9.   

    if (!this.IsPostBack) {
                //Dropdownlis数据帮定代码
     }
    这个有道理
      

  10.   

    把dropdownlist的autopostback设置为true然后在page_load里添加
    在aspx业面添加<asp:dropdownlist id="ddl" runat="server" onselectindexchanged="ddl_selectindexchanged"></asp:dropdownlist>
    if(!Page.IsPostBack)
    {
      bindddl();//绑定dropdownlist的方法
    }
    private void ddl_selectindexchanged(object sender,System.EventArgs e)
    {
     //添加需要的代码..
    }
    这样就可以了哦。。
      

  11.   

    private void Page_Load(object sender, System.EventArgs e)
    {
    Response.Expires = 0;
    if (!this.IsPostBack)
    {
    邦定事件:
    this.ddl.DataTextField=AttachmentMapping.FileName;
    this.ddl.DataValueField=AttachmentMapping.NewsID;
    this.drpupfile.DataSource=dt;
    this.drpupfile.DataBind();}
    委托事件:
    private void InitializeComponent()
    {    
    this.ddl.SelectedIndexChanged += new System.EventHandler(this.ddl_SelectedIndexChanged);
    this.Load += new System.EventHandler(this.Page_Load); }WEB页面端的设置:<asp:dropdownlist id="ddl" style="Z-INDEX: 102; LEFT: 104px; POSITION: absolute; TOP: 456px"runat="server" Height="24px" Width="80px" AutoPostBack="True"></asp:dropdownlist>
      

  12.   

    AutoPostBack设置为TRUE和FALSE都不可用
      

  13.   

    PageLoad里面加上
     if(!Page.IsPostBack)
     {}然后将Dropdownlist的AutoPostBack 设置成 True;
      

  14.   

    检查你各个选项的Value是否是重复值?
    这个SelectedIndexChanged 事件的名字比较具有欺骗性,其实不是在Index变化的时候触发,而是Value变化的时候触发的。