我對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小時)如果您有任何疑問......我會在那裏回答你。