Cascading Dropdown Getting Error Not all code return value
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">
<asp:DropDownList ID="DdlTapeCode" runat="server"
Height="22px"
Width="317px" >
</asp:DropDownList>
<ajaxToolkit:CascadingDropDow开发者_运维技巧n 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>
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
精彩评论