[WebMethod] public CascadingDropDownNameValue[] GetGrandParentServices(string knownCategoryValues) { string query = "SELECT ServiceType FROM ServiceType Where ParentServiceID IS NULL"; List<CascadingDropDownNameValue> serviceType = GetData(query); return serviceType.ToArray(); } [WebMethod] public CascadingDropDownNameValue[] GetParentServices(string knownCategoryValues) { string parentService = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues)["ServiceType"]; string query = string.Format("SELECT DISTINCT ParentService FROM Service WHERE GrandParentService = '{0}'", parentService); List<CascadingDropDownNameValue> services = GetData(query); return services.ToArray(); } private List<CascadingDropDownNameValue> GetData(string query) { string conString = ConfigurationManager.ConnectionStrings["conString"].ConnectionString; SqlCommand cmd = new SqlCommand(query); List<CascadingDropDownNameValue> values = new List<CascadingDropDownNameValue>(); using (SqlConnection con = new SqlConnection(conString)) { con.Open(); cmd.Connection = con; using (SqlDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) { values.Add(new CascadingDropDownNameValue { name = reader[0].ToString(), value = reader[0].ToString() }); } reader.Close(); con.Close(); return values; } } }
<pre lang="HTML"><EditItemTemplate> <asp:DropDownList ID="ddlGrandParentService" runat="server" Width="150"> </asp:DropDownList> <cc1:CascadingDropDown ID="cdlGrandParentService" TargetControlID="ddlGrandParentService" PromptText="Select Parent Service" PromptValue="" ServicePath="http://localhost:1232/ServiceCS.asmx" ServiceMethod="GetGrandParentServices" runat="server" Category="ServiceType" /> </EditItemTemplate> <EditItemTemplate> <asp:DropDownList ID="ddlParentService" runat="server" Width="150"> </asp:DropDownList> <cc1:CascadingDropDown ID="cdlParentService" TargetControlID="ddlParentService" PromptText="Select Parent Service" PromptValue="" ServicePath="http://localhost:1232/ServiceCS.asmx" ServiceMethod="GetParentServices" runat="server" Category="ParentService" ParentControlID="ddlGrandParentService" /> </EditItemTemplate>
int GrandParentServiceId = Convert.ToInt32(((DropDownList)GridView1.Rows[e.RowIndex].FindControl("ddlGrandParentService")).SelectedItem.Value); int ParentServiceId = Convert.ToInt32(((DropDownList)GridView1.Rows[e.RowIndex].FindControl("ddlParentService")).SelectedItem.Value);
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)