0

我在用户控件中有一个下拉列表,如下所示

   <asp:dropdownlist id="ddlLanguage" runat="server" AutoPostBack="true" EnableViewState="true" onselectedindexchanged="ddlLanguage_SelectedIndexChanged">
        </asp:dropdownlist>

我的 selectedchanged 事件甚至没有被触发一次

在后面的代码中

if (!IsPostBack)
{
  //dt - is list of languages availbale in DB
 //value[0]-contains lang currently to be binded to dropdownlist based
 //remaining values (values [1]) to are to be populated to textbox
  LoadModuleInfo(dt,values)
}

     private void LoadModuleInfo(System.Data.DataTable dtLanguages, string[] values)
    {
        this.txbxModuleName.Text = values[1];

        this.ddlLanguage.DataSource = dtLanguages;
        this.ddlLanguage.DataTextField = "language_description";
        this.ddlLanguage.DataValueField = "language";
        this.ddlLanguage.DataBind();

        // set up selections on the screen 

        this.ddlLanguage.SelectedIndex = this.getIndex(dtLanguages, values[0]);

    }

  protected void ddlLanguage_SelectedIndexChanged(object sender, System.EventArgs e)
    {
          //get new values ( values[0] and values[1])
         LoadModuleInfo(dtLanguages, values);
     }

 protected int getIndex(DataTable dt, string recordId)
  {
    int intCt = 0;

    foreach (System.Data.DataRow dr in dt.Rows)
    {
        if (dr[0].ToString() == recordId)
        {
            break;
        }
        else
        {
            intCt++;
        }
    }

    return intCt;
}

我已经编写了上面的代码,但是对于 USERCONTROL 中可用的下拉列表控件,不会触发 selectedchanged 事件。

请帮忙。

4

2 回答 2

0

如果您的页面根本没有刷新 .. 很可能您的页面中有 javascript 错误

于 2013-09-17T14:02:14.160 回答
0

请从您的代码中删除以下行并尝试

this.ddlLanguage.DataValueField = "language";

或者

将其更改为language_description

于 2016-12-03T07:03:19.457 回答