Note that there are some explanatory texts on larger screens.

plurals
  1. POCascading dropdowns for C# ASP.NET
    primarykey
    data
    text
    <p>I'm trying to create some cascading drop downs. I have my States loading via C# page load fine. I just can't seem to get anything to fire off to load the cities. After the cities, I'll be adding another drop down, but I can figure that out once I have this working.</p> <p>I did notice "Default.aspx/LoadCitiesByState 500 (Internal Server Error)" in my Chrome errors.</p> <p><strong>C#</strong></p> <pre><code> protected void LoadStates() { // Populate State dropdown box ListItem li = new ListItem(); li.Value = "0"; li.Text = "Select One"; DataSet dsState = SharedData.GetStates(); ddlState.DataSource = dsState.Tables[0].DefaultView; ddlState.DataValueField = "ab"; ddlState.DataTextField = "name"; ddlState.DataBind(); ddlState.Items.Insert(0, li); } [WebMethod] protected void LoadCitiesByState(string state) { ListItem li = new ListItem(); li.Value = "0"; li.Text = "Select One"; DataTable dt = new DataTable(); dt = SharedData.GetCities(state); ddlCity.DataSource = dt.Rows[0].Table.DefaultView; ddlCity.DataValueField = "ListCity"; ddlCity.DataTextField = "ListCity"; ddlCity.DataBind(); ddlCity.Items.Insert(0, li); } </code></pre> <p><strong>Markup</strong></p> <pre><code>&lt;asp:DropDownList ID="state" runat="server" MaxLength="50" Style="width: 200px;" /&gt; &lt;asp:DropDownList ID="city" runat="server" MaxLength="50" Style="width: 200px;" /&gt; function loadCities(selectedItem) { $.ajax({ type: "POST", url: "Default.aspx/LoadCitiesByState", data: "selectedItem", contentType: "application/json; charset=utf-8", dataType: "json", async: true, success: function Success(data) { alert(selectedItem); } }); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload