Click here to Skip to main content
15,896,606 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i searched lot in google but did not get sufficient answer..any help will be appreciated....

Code from comments:
web service code is...
C#
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// 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 CasCadingDropDown : System.Web.Services.WebService
{
    //private DataSet ds = new DataSet();
    //private DataTable dt = new DataTable();
    public CasCadingDropDown()
    {

        //Uncomment the following line if using designed components 
        //InitializeComponent(); 
    }

    [WebMethod]
    public CascadingDropDownNameValue[] GetStates(string knownCategoryValues)
    {
        string query = "SELECT statename, stateid FROM tblstates";
        List<CascadingDropDownNameValue> states = GetData(query);
        return states.ToArray();
    }

    [WebMethod]
    public CascadingDropDownNameValue[] GetDistricts(int state)
    {
        //int state = Formats.ConvertToInt(CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues)["stateid"]);
        string query = string.Format("select districtname,districtid from tbldistricts where stateid={0}",state);
        List<CascadingDropDownNameValue> districts = GetData(query);
        return districts.ToArray();
    }
    private List<CascadingDropDownNameValue> GetData(string query)
    {
        
    string connstring = String.Format("Server=192.168.1.100;Port=5432;Encoding=UNICODE;User Id=postgres;Password=sggkishore;Database=SNCF;");
         NpgsqlCommand cmd = new NpgsqlCommand(query);
        List<CascadingDropDownNameValue> values = new List<CascadingDropDownNameValue>();
        using (NpgsqlConnection conn = new NpgsqlConnection(connstring))
        {
            conn.Open();
            cmd.Connection = conn;
            using (NpgsqlDataReader reader = cmd.ExecuteReader())
            {
                while (reader.Read())
                {
                    values.Add(new CascadingDropDownNameValue
                    {
                        name = reader[0].ToString(),
                        value = reader[1].ToString()
                    });
                }
                reader.Close();
                conn.Close();
                return values;
            }
        }
    }

and textbox code is
ASP.NET
<asp:DropDownList ID="ddlCState" runat="server" CssClass ="userentry" >
                                 <cc1:CascadingDropDown ID="cdlStates" TargetControlID="ddlCState" PromptText="Select State" 
                                  ServicePath="CascadingDropdown.asmx" ServiceMethod="GetStates"  runat="server" Category="StateId" />
Posted
Updated 5-Oct-15 19:55pm
v3
Comments
Member 12003400 5-Oct-15 6:41am    
Question is not sufficient, ,, Pls upload code or elaborate ..
Naveen.Sanagasetti 5-Oct-15 6:49am    
Please improve your question to get more +ve responses.
Richard Deeming 5-Oct-15 8:49am    
Don't use the comments to post your code - use the "Improve question" button at the bottom of the question.

I've added the code to your question.
User-11630313 5-Oct-15 9:11am    
k.and thank you
Richard Deeming 5-Oct-15 9:13am    
Your code is potentially vulnerable to SQL Injection[^]. NEVER use string concatenation to build a SQL query. ALWAYS use a parameterized query.

In this particular instance, since the parameter is already validated to be an integer, it can't be exploited. However, it's far too easy to get into the habit of using string concatenation for "safe" cases, and then forget to use parameters in unsafe cases.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900