我对Visual Studio相当陌生。我正在Visual Studio Express 2013上工作,我试图在ASP.net中填充特定的文本框从DropDownList填充文本框选择用CascadingDropDown填充本身
我会尽我所能地总结一切(我不是英语母语的人)
首先我遇到了这个无效回传的问题。我发现只有一个正确的解决方案就在这里:https://johanleino.wordpress.com/2009/11/17/cascadingdropdown-causes-invalid-postback-or-callback-argument-error/ 所以,这就是为什么我有NoValidationDropDownList,而不是传统的下拉列表
而且,我必须使用AJAX CascadingDropDown 2 DropDownList的(我填的第二个取决于所选择第一个值)
这是我的观点:
<asp:TableCell>
<asp:NoValidationDropDownList OnSelectedIndexChanged="DropDownListVille_SelectedIndexChanged" ID="DropDownListVille" runat="server" class="ddlVille" ></asp:NoValidationDropDownList>
<ajax:CascadingDropDown ID="CascadingDropDown1" runat="server" Category="Ville"
TargetControlID="DropDownListVille" PromptText="Non définie" LoadingText="Chargement des villes"
ServiceMethod="AfficherVille" ServicePath="CascadingDropDown.asmx"></ajax:CascadingDropDown>
</asp:TableCell>
<asp:TableCell runat="server">
<asp:NoValidationDropDownList ID="DropDownListRue" runat="server" class="ddlRue" OnSelectedIndexChanged="DropDownListVille_SelectedIndexChanged"></asp:NoValidationDropDownList>
<ajax:CascadingDropDown ID="ccdRegion" runat="server" Category="Rue" ParentControlID="DropDownListVille"
TargetControlID="DropDownListRue" PromptText="Non définie" LoadingText="Chargement des rues"
ServiceMethod="VilleRueLier" ServicePath="CascadingDropDown.asmx"></ajax:CascadingDropDown>
</asp:TableCell>
<asp:TableCell>
<asp:TextBox ID="TextBoxCP" runat="server" class="tbcp"></asp:TextBox>
</asp:TableCell>
我的第一个下拉有城市,第二个有一个街道,我的文本框有邮政编码。所有数据从一个DB使用这两个表来:
威乐(Id_Ville,nom_ville,code_postal) 翻译在
city(id_city,city_name,postcode)
街(Id_Rue,Nom_Rue) 翻译在
street(id_street,street_name)
我想根据所选城市的ID动态更改邮编(此ID在下拉列表中存储为一个值)。
看到用户想要的城市不在分贝时,他可以选择第一个下拉框的特殊值,并添加一个新城市。
当他这样做时,页面会显示一些带有ajax的文本框。
在那里,用户可以添加一个新的城市及其邮编。否则,邮编文本框是只读的。
但是,当他选择一个上市城市时,我希望文本框填充自己。
有我的web服务方法,联系到cascadingDropDown:
[System.Web.Script.Services.ScriptService()]
public class WebService1 : System.Web.Services.WebService
{
private Passerelle.Passerelle passerelle = new Passerelle.Passerelle();
[WebMethod]
public CascadingDropDownNameValue[] AfficherVille(string knownCategoryValues, string category)
{
List<CascadingDropDownNameValue> VilleDetails = new List<CascadingDropDownNameValue>();
ListVille listeVille = new ListVille();
listeVille = passerelle.getListVille();
foreach (Ville v in listeVille.List)
{
string idVille = v.IdVille.ToString();
string nomVille = v.NomVille.ToString();
VilleDetails.Add(new CascadingDropDownNameValue(nomVille, idVille));
Debug.WriteLine("Id Ville = " + idVille + " ----- NomVille = " + nomVille);
}
return VilleDetails.ToArray();
}
[WebMethod]
public CascadingDropDownNameValue[] VilleRueLier(string knownCategoryValues, string category)
{
///GET DATA FROM SQL
ListRue listeRue = new ListRue();
StringDictionary VilleDetails = AjaxControlToolkit.CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);
int idVille = Convert.ToInt32(VilleDetails["Ville"]);
List<CascadingDropDownNameValue> countrydetails = new List<CascadingDropDownNameValue>();
//Here I get the data from my table 'Rue' with the ID coming from
listeRue = passerelle.getListRue(idVille);
countrydetails.Add(new CascadingDropDownNameValue("Pas dans la liste", "-1"));
foreach (Rue r in listeRue.list)
{
string idRue = r.idRue.ToString();
string nomRue = r.nomRue.ToString();
countrydetails.Add(new CascadingDropDownNameValue(nomRue, idRue));
Debug.WriteLine("Id rue = " + idRue + " ----- NomRue = " + nomRue);
}
return countrydetails.ToArray();
}
}
我试过很多东西...经典事件,一些Ajax功能调用。 而我只是不知道该怎么做...
当然,我遵循经典的MVC模式。所以...视图中没有sql请求。
我不擅长ajax。 我可能会错过一些伟大的ajax/asp.net功能与另一个webMethod。
非常感谢任何能够帮助我的人。
抱歉所有的拼写/语法错误。
我将无法回答几个小时(我会回来的东西约12小时)如果您有任何疑问......我会在那里回答你。