0

I have two dropdown. and I am using Cascading dropdown.My First dropdown is returning result on click of selected data from 1st dropdown it is showing no records for those dont have value. But for selected data which has related data its showing method error. can anybody suggest whats the problem? While In sql server I am getting answer values. DD_Issue is view and tape_master is table in database.

Webservice:-

using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Services; using System.Data; using System.Data.SqlClient; using System.Configuration; using System.Collections.Specialized; using System.Web.Script.Services; using AjaxControlToolkit; using System.Diagnostics;

/// /// Summary description for TapeWebService /// /// ///

[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 TapeWebService : System.Web.Services.WebService { SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["kk"].ToString());

DataSet ds;
IssueReturn ir;
SqlCommand cmd;
SqlDataAdapter sda;
public TapeWebService()
{

    //Uncomment the following line if using designed components 
    //InitializeComponent(); 
}
[ScriptMethod]
[WebMethod]
public AjaxControlToolkit.CascadingDropDownNameValue[] FillTape(string knownCategoryValues,string category)
    {
        try
        {
            con.Open();
            cmd = new SqlCommand("Select id, t_code from tape_master", con);
            cmd.ExecuteNonQuery();
            sda = new SqlDataAdapter(cmd);
            ds = new DataSet();
            sda.Fill(ds);
            con.Close();
            List<AjaxControlToolkit.CascadingDropDownNameValue> Tape = new List<AjaxControlToolkit.CascadingDropDownNameValue>();
            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                string TapeID = Convert.ToString( dr["id"].ToString());
                string TapeName = dr["t_code"].ToString();
                Tape.Add(new AjaxControlToolkit.CascadingDropDownNameValue(TapeName, TapeID));
            }
            return Tape.ToArray();
        }
        catch (Exception e)
        { 

            string message = e.Message;
            HttpContext.Current.Response.Write(e.Message);
        }
}
[ScriptMethod]
[WebMethod]
public AjaxControlToolkit.CascadingDropDownNameValue[] FillTapeCode(string knownCategoryValues, string category)
{
    try
    {
      string TapeID;
        StringDictionary Tape = AjaxControlToolkit.CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);
        TapeID = Convert.ToString(Tape["Tape"]);
        con.Open();
        cmd = new SqlCommand("Select * from DD_Issue where tapetype='" + TapeID + "'", con);
        cmd.Parameters.AddWithValue("id", TapeID);
        cmd.ExecuteNonQuery();
        sda = new SqlDataAdapter(cmd);
        ds = new DataSet();
        sda.Fill(ds);
        con.Close();
        List<AjaxControlToolkit.CascadingDropDownNameValue> Code = new List<AjaxControlToolkit.CascadingDropDownNameValue>();
        foreach (DataRow dr in ds.Tables[0].Rows)
        {
            string TapeCodeID = Convert.ToString(dr["id"].ToString());
            string TapeCodeName = dr["fill"].ToString();
            Code.Add(new AjaxControlToolkit.CascadingDropDownNameValue(TapeCodeName, TapeCodeID));
        }
        return Code.ToArray();
    }
    catch(Exception e)
    {
        string message = e.Message;
        HttpContext.Current.Response.Write(e.Message);
    }
}

.Aspx page:-

<asp:DropDownList ID="DdlTapeType" runat="server" Width="140px" 
                                                                        Height="22px">
                                                                    </asp:DropDownList>

                                                                   <ajaxToolkit:CascadingDropDown ID="CascadingDDtape" runat="server" Category="Tape"
                                                          TargetControlID="DdlTapeType" LoadingText="[Loading ...]"
                                                           PromptText="Please select a Tape" 
                                                ServicePath="TapeWebService.asmx" ServiceMethod="FillTape">

                                                                    </ajaxToolkit:CascadingDropDown> 

                                                                </td>
                                                                <td class="style31">
                                                                    &nbsp;<asp:DropDownList ID="DdlTapeCode" runat="server" 
                                                                        Height="22px" 
                                                                        Width="317px" >
                                                                    </asp:DropDownList>

                                                                     <ajaxToolkit:CascadingDropDown ID="CascadingDDCode" runat="server" 
                                                        TargetControlID="DdlTapeCode" LoadingText="[Loading ...]"
                                                        PromptText="Please select a Code" EmptyText="No Records" ServicePath="TapeWebService.asmx" 
                                                        ServiceMethod="FillTapeCode" Category="Code" ParentControlID="DdlTapeType">
                                                                    </ajaxToolkit:CascadingDropDown>

1 Answer 1

0

You are getting this error because there is no return statement in catch block. You have given return in Try {} only, include return in catch also.

public AjaxControlToolkit.CascadingDropDownNameValue[] FillTape(string knownCategoryValues,string category)
    {
 List<AjaxControlToolkit.CascadingDropDownNameValue> Tape = new List<AjaxControlToolkit.CascadingDropDownNameValue>();
        try
        {
            con.Open();
            cmd = new SqlCommand("Select id, t_code from tape_master", con);
            cmd.ExecuteNonQuery();
            sda = new SqlDataAdapter(cmd);
            ds = new DataSet();
            sda.Fill(ds);
            con.Close();

            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                string TapeID = Convert.ToString( dr["id"].ToString());
                string TapeName = dr["t_code"].ToString();
                Tape.Add(new AjaxControlToolkit.CascadingDropDownNameValue(TapeName, TapeID));
            }

        }
        catch (Exception e)
        { 

            string message = e.Message;
            HttpContext.Current.Response.Write(e.Message);
        }
return Tape.ToArray();
}
[ScriptMethod]
[WebMethod]
public AjaxControlToolkit.CascadingDropDownNameValue[] FillTapeCode(string knownCategoryValues, string category)
{
     List<AjaxControlToolkit.CascadingDropDownNameValue> Code = new List<AjaxControlToolkit.CascadingDropDownNameValue>();
    try
    {
      string TapeID;
        StringDictionary Tape = AjaxControlToolkit.CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);
        TapeID = Convert.ToString(Tape["Tape"]);
        con.Open();
        cmd = new SqlCommand("Select * from DD_Issue where tapetype='" + TapeID + "'", con);
        cmd.Parameters.AddWithValue("id", TapeID);
        cmd.ExecuteNonQuery();
        sda = new SqlDataAdapter(cmd);
        ds = new DataSet();
        sda.Fill(ds);
        con.Close();

        foreach (DataRow dr in ds.Tables[0].Rows)
        {
            string TapeCodeID = Convert.ToString(dr["id"].ToString());
            string TapeCodeName = dr["fill"].ToString();
            Code.Add(new AjaxControlToolkit.CascadingDropDownNameValue(TapeCodeName, TapeCodeID));
        }

    }
    catch(Exception e)
    {
        string message = e.Message;
        HttpContext.Current.Response.Write(e.Message);
    }
 return Code.ToArray();
}

Thanks Ashwani

Sign up to request clarification or add additional context in comments.

8 Comments

@Ashwani so what i have to write in return i am not getting can u help?
thank you so much for looking on my question but my problem still persist As getting error in 2nd dropdown "method error 500"
Can you post the stack trace if any exception is generated?
@Ashwani-Thank you so much for looking in d problem.Actually I am not getting any stack trace.Page get loaded easily all other controls working fine.Only cascading dropdown is creating problem.In it 1st dropdown shows data from web service. In my 1st drop down selected field which dont have further data it is showing "No Records" which is right. but from the 1st dropdown who has corresponding further value is not getting populated for it,its showing "method error 500" in dropdown list
Try to debug the method which is called for binding (FillTapeCode)?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.