简体   繁体   English

HTMLselect选定索引已更改事件

[英]Htmlselect selected index changed event

I have 2 HtmlSelect controls and i need to load second one according to first HtmlSelect's selected index. 我有2个HtmlSelect控件,我需要根据第一个HtmlSelect的选定索引加载第二个。 But it doesn't work, because HtmlSelect doesnt have selectedindexchanged event. 但这不起作用,因为HtmlSelect没有selectedindexchanged事件。 What do i need to do? 我需要做什么? Any idea? 任何想法?

Example; 例;

<!--These are my Html Select controls-->

 select runat="server" id="drpCity"></select> 
 <select runat="server" id="drpState">/select>



  protected void Page_Load(object sender, EventArgs e)
  {
     FillCities(drpCity);
     FillStates(drpState, drpCity.SelectedValue);
  }

  public void FillCitiesHtmlSelect(HtmlSelect drpCity)
        {
           BusCity busCity = new BusCity();
           List<EntCity> lentCity = busCity.SearchAll();
           drpCity.DataValueField = EntCity.Columns.CITYCODE;
           drpCity.DataTextField = EntCity.Columns.CITYNAME;
           drpCity.DataSource = lentCity;
           drpCity.DataBind();

            drpCity.Items.Insert(0, new ListItem("City", string.Empty));
        }

public void FillStatesHtmlSelect(HtmlSelect drpState, string cityCode)
{
    if (!string.IsNullOrEmpty(cityCode))
       {
          BusState busState = new BusState();
          List<EntState> lentEmsState = busState.Search(cityCode);
          drpState.DataValueField = EntState.Columns.STATECODE;
          drpState.DataTextField = EntState.Columns.STATENAME;
          drpState.DataSource = lentState;
          drpState.DataBind();
        }
        else
        {
          drpState.Items.Clear();
        }
           drpState.Items.Insert(0, "State", string.Empty));
   }

I can suggest an approach, though i have not implemented it. 我可以建议一种方法,尽管我尚未实现。 If you can call a javascript function from your one select control to check for a non-default value and if the condition meets, load the second select html. 如果您可以从一个选择控件中调用javascript函数来检查非默认值,并且满足条件,请加载第二个选择html。

HTML select控件没有'selectedindexchanged'事件,而是客户端事件'onchange'。同样,您不能从html select控件调用服务器端。要调用在C#代码页(服务器端)中编写的函数,您需要使用webservice将您的C#函数定义为webmethord,并在html select控件的“ onchange”事件中使用网络服务调用函数。

暂无
暂无

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

相关问题 组合框选择的索引更改事件未在代码中触发 - Combobox selected index changed event not fired in code 调用dropdownlist选择索引已手动更改事件 - call dropdownlist selected index changed event manually 当选定索引更改事件时,dhtml弹出窗口消失 - dhtml popup window disappear when selected index changed event 选定的索引更改事件未同时触发两个自动回发属性 - Selected Index Changed event not firing both Autopostback property 在页面加载期间的数据绑定期间,未为DropDownList触发选定索引已更改事件 - Selected Index Changed event not firing for a DropDownList during databind at pageload 在事件处理程序之外的代码隐藏部分中,确定是否更改了所选索引或触发了自动回发事件 - Determine whether the selected index was changed or an autopostback event was triggered, in sections of the code-behind other than the event handler 不会针对在运行时创建的下拉列表触发选定的索引更改事件 - doesn't fire selected index changed event for a drop down list created on run time 如何在C#中为下拉选择的索引更改事件编写JavaScript验证 - how to write javascript validation for dropdown selected index changed event in c# html select(下拉)控制在asp.net中选择的索引已更改事件 - html select (dropdown) control selected index changed event in asp.net 如何在单个Windows窗体的多个列表视图中使用选定的索引更改事件? - how to use selected index changed event in multiple listviews in single windows form?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM