ajax级联下拉列表 [英] ajax cascading dropdown list

查看:94
本文介绍了ajax级联下拉列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 am 使用 ajax级联下拉列表页面加载时希望下拉列表应该选择到我在数据库中存储而不是选择国家/地区选项的国家/地区应      我的代码


public CascadingDropDownNameValue [] GetCountry( string knownCategoryValues, string category)
{

MNBusinessLogic.Admin adm = new MNBusinessLogic.Admin();
DataSet dsUpdate = adm.GetMasters( 0 国家/地区 0 true );
List< CascadingDropDownNameValue> countrydetails = new 列表< CascadingDropDownNameValue>();
if (dsUpdate!= null && dsUpdate.Tables.Count > 0 && dsUpdate.Tables [ 0 ]。Rows.Count > 0
{
foreach (DataRow dtrow in dsUpdate.Tables [ 0 ] .Raw)
{
string CountryID = dtrow [ UID]的ToString();
string CountryName = dtrow [ MasterKey ]的ToString();
countrydetails.Add( new CascadingDropDownNameValue(CountryName,CountryID));
}

}
return countrydetails.ToArray();
}

和aspx代码

< asp:DropDownList ID = ddlC runat = server >
< / asp:DropDownList >
< ajaxToolkit:CascadingDropDown ID = cascadingddlC runat = server TargetControlID = ddlC PromptText = 选择国家/地区 LoadingText = 正在加载类别= 国家/地区 ServiceMethod = GetCountry ServicePath = cascadingHelper.asmx >
< / ajaxToolkit:CascadingDropDown >

解决方案

我得到的答案我只需添加一行代码



 cascadingddlC.SelectedValue = ds1.Tables [0] .Rows [0] [Country]。ToString(); 


am using ajax cascading dropdownlist when the page gets load i want the dropdownlist should be selected to the country which i had store in database instead of select country option what i should do for it this is my code


public CascadingDropDownNameValue[] GetCountry(string knownCategoryValues, string category)
        {

            MNBusinessLogic.Admin adm = new MNBusinessLogic.Admin();
            DataSet dsUpdate = adm.GetMasters(0, "Country", 0, true, false);
            List<CascadingDropDownNameValue> countrydetails = new List<CascadingDropDownNameValue>();
            if (dsUpdate != null && dsUpdate.Tables.Count > 0 && dsUpdate.Tables[0].Rows.Count > 0)
            {
                foreach (DataRow dtrow in dsUpdate.Tables[0].Rows)
                {
                    string CountryID = dtrow["uid"].ToString();
                    string CountryName = dtrow["MasterKey"].ToString();
                    countrydetails.Add(new CascadingDropDownNameValue(CountryName, CountryID));
                }
                
            }
            return countrydetails.ToArray();
        }

and aspx code is

 <asp:DropDownList ID="ddlC" runat="server">
         </asp:DropDownList>
          <ajaxToolkit:CascadingDropDown ID="cascadingddlC"  runat="server"                        TargetControlID="ddlC" PromptText="Select Country" LoadingText="Loading" Category="Country" ServiceMethod="GetCountry"  ServicePath="cascadingHelper.asmx">
               </ajaxToolkit:CascadingDropDown>

解决方案

i got the answer i had to just add a line of code

cascadingddlC.SelectedValue = ds1.Tables[0].Rows[0]["Country"].ToString();


这篇关于ajax级联下拉列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆