<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="available_services.aspx.cs" MasterPageFile="~/Forms/Home.Master" Inherits="HospitalManagementSystem.Forms.available_services" %> <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %> <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server"> <script type="text/javascript" src="scripts/jquery-1.10.1.min.js"></script> <div> <ajaxToolkit:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"> </ajaxToolkit:ToolkitScriptManager> <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false"> <Columns> <asp:BoundField HeaderText="Name" DataField="ContactName" /> <asp:TemplateField HeaderText="Country"> <ItemTemplate> <asp:DropDownList ID="ddlCountries" runat="server" Width="150"> </asp:DropDownList> <cc1:CascadingDropDown ID="cdlCountries" TargetControlID="ddlCountries" PromptText="Select Country" PromptValue="" ServicePath="ServiceCS.asmx" ServiceMethod="GetCountries" runat="server" Category="Country" /> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="City"> <ItemTemplate> <asp:DropDownList ID="ddlCities" runat="server" Width="150"> </asp:DropDownList> <cc1:CascadingDropDown ID="cdlCities" TargetControlID="ddlCities" PromptText="Select City" PromptValue="" ServicePath="ServiceCS.asmx" ServiceMethod="GetCities" runat="server" Category="City" ParentControlID="ddlCountries" /> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView> </div> </asp:Content>
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data; using System.Configuration; using System.Data.SqlClient; using System.Web.Services; using AjaxControlToolkit; namespace Testing.Forms { public partial class available_services : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) //Only do this first time it's loaded { BindMajorHeadDropdown(); GridView1.DataSource = GetData("SELECT TOP 10 ContactName, Country FROM Customers"); GridView1.DataBind(); } } private DataSet GetData(string query) { string conString = ConfigurationManager.ConnectionStrings["conString"].ConnectionString; SqlCommand cmd = new SqlCommand(query); using (SqlConnection con = new SqlConnection(conString)) { using (SqlDataAdapter sda = new SqlDataAdapter()) { cmd.Connection = con; sda.SelectCommand = cmd; using (DataSet ds = new DataSet()) { sda.Fill(ds); return ds; } } } } }
using System; using System.Collections.Generic; using System.Web; using System.Web.Services; using System.Data; using System.Data.SqlClient; using System.Configuration; using AjaxControlToolkit; namespace Testing { /// <summary> /// Summary description for ServiceCS /// </summary> [WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] [System.ComponentModel.ToolboxItem(false)] // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. [System.Web.Script.Services.ScriptService] public class ServiceCS : System.Web.Services.WebService { [WebMethod] public CascadingDropDownNameValue[] GetCountries(string knownCategoryValues) { string query = "SELECT DISTINCT Country FROM Customers"; List<CascadingDropDownNameValue> countries = GetData(query); return countries.ToArray(); } [WebMethod] public CascadingDropDownNameValue[] GetCities(string knownCategoryValues) { string country = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues)["Country"]; string query = string.Format("SELECT DISTINCT City FROM Customers WHERE Country = '{0}'", country); List<CascadingDropDownNameValue> cities = GetData(query); return cities.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; } } } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)