我有两个下拉列表。我正在使用级联下拉列表。我的第一个下拉列表是从第一个下拉列表中点击所选数据返回结果,它显示没有那些没有值的记录。但对于具有相关数据的选定数据,其显示方法错误。任何人都可以建议这个问题是什么?在sql server中我得到了答案值。 DD_Issue是view,tape_master是数据库中的表。
web服务: -
使用System; 使用System.Collections.Generic; 使用System.Linq; 使用System.Web; 使用System.Web.Services; 使用System.Data; 使用System.Data.SqlClient; 使用System.Configuration; 使用System.Collections.Specialized; 使用System.Web.Script.Services; 使用AjaxControlToolkit; 使用System.Diagnostics;
/// /// TapeWebService的摘要描述 /// /// ///
[WebService(Namespace =“http://tempuri.org/”)] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
//要允许使用ASP.NET AJAX从脚本调用此Web Service,请取消注释以下行。 [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页面: -
<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: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>
答案 0 :(得分:0)
您收到此错误,因为catch块中没有return语句。您只在Try {}中返回,包括在catch中返回。
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();
}
由于 Ashwani