我有兩個下拉菜單。我使用的是Cascading dropdown.My First dropdown is returned result on click of selected data from 1st dropdown that is no records for those does not have value。但對於具有相關數據的選定數據,其顯示方法錯誤。有誰可以提出什麼問題?而在sql服務器,我得到的答案值。 DD_Issue是view和tape_master是數據庫中的表。級聯下拉式獲取錯誤不是所有的代碼返回值
Webservice: -
using System; using System.Collections.Generic;使用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;使用AjaxControlToolkit的 ; using System.Diagnostics;對於TapeWebService
/// ///概要描述/// /// ///
[WebService的(命名空間= 「http://tempuri.org/」)] [ WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
//若要允許使用ASP.NET AJAX從腳本調用此Web服務,請取消註釋以下行。 [System.Web.Script.Services.ScriptService]
公共類TapeWebService:System.Web.Services.WebService { 的SqlConnection CON =新的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>
@Ashwani所以我有什麼回報我沒有得到u能幫助寫? – Aishna
已更新回覆 –
非常感謝您關注我的問題,但我的問題仍然存在由於第二個下拉列表中出現錯誤「方法錯誤500」 – Aishna