private const int ItemsPerRequest = 10;
[WebMethod]
public RadComboBoxItemData[] GetAccount(object context)
{
RadComboBoxContext obj = (RadComboBoxContext)context;
DataTable data = GetDataAccount(obj.Text);
RadComboBoxData comboData = new RadComboBoxData();
int itemOffset = obj.NumberOfItems;
int endOffset = Math.Min(itemOffset + ItemsPerRequest, data.Rows.Count);
comboData.EndOfItems = endOffset == data.Rows.Count;
List result = new List(endOffset - itemOffset);
for (int i = itemOffset; i < endOffset; i++)
{
RadComboBoxItemData itemData = new RadComboBoxItemData();
itemData.Value = data.Rows[i]["AccountLevelNo"].ToString();
itemData.Text = data.Rows[i]["AccountDesc3"].ToString();
itemData.Attributes.Add("Level6", data.Rows[i]["AccountDesc2"].ToString());
itemData.Attributes.Add("Level1", data.Rows[i]["AccountDesc1"].ToString());
result.Add(itemData);
}
comboData.Items = result.ToArray();
// comboData.Message = GetStatusMessage(endOffset, data.Rows.Count);
return comboData.Items.ToArray();
}
private static DataTable GetDataAccount(string text)
{
int accCode = 0;
string query = "select COA.LevelAccountNo,COA.AccountDesc as AccountDesc3,Level1.AccountDesc as AccountDesc1, Level2.AccountDesc as AccountDesc2 from COA COA,(select LevelAccountNo,AccountDesc " +
"from COA where len(LevelAccountNo)=2)as Level1,(select LevelAccountNo,AccountDesc from COA where len(LevelAccountNo)=5)as Level2 " +
"where Level1.LevelAccountNo=left(COA.LevelAccountNo,2)and Level2.LevelAccountNo=left(COA.LevelAccountNo,5) and len(COA.LevelAccountNo)>6";
try
{
accCode = Convert.ToInt32(text);
query = query + " COA.LevelAccountNo like '" + text + "%'";
}
catch (Exception ex)
{
query = query + " COA.AccountDesc3 like '%" + text + "%'";
}
SqlConnection con = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"].ToString());
// string constr=ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
SqlDataAdapter adapter = new SqlDataAdapter(query, con);
// adapter.SelectCommand.Parameters.AddWithValue("@text", text);
DataTable data = new DataTable();
adapter.Fill(data);
con.Close();
return data;
}
这是我的网络服务代码
Collapse | Copy Code
<telerik:RadComboBox ID="cboAccount" runat="server" Height="200" Width="200" EmptyMessage="Select an Account"
EnableLoadOnDemand="true" ShowMoreResultsBox="true" EnableVirtualScrolling="true">
<HeaderTemplate>
<h3>Accounts</h3>
</HeaderTemplate>
<ClientItemTemplate>
<div>
<ul>
<li><span><b>Name:#= Text # </b></span></li>
<li><span>Level6 #= Attributes.Level6 # </span></li>
<li><span>Level1: #= Attributes.Level4 # </span></li>
<li><span>Level4 #= Attributes.Level1 # </span></li>
</ul>
</div>
<br></br>
</ClientItemTemplate>
<WebServiceSettings Method="GetAccount" Path="InvestmentDropDownWebService.asmx" />
</telerik:RadComboBox>
我在我的项目中第一次使用 web 服务。我不知道如何解决这个错误。如果我正在运行,aspx.cs
这是完美的运行,并且值绑定在组合框中。但是,当我使用 Web 服务将值绑定到组合框时,它会给出一个错误:
不支持 Telerik.Web.UI.RadComboBoxContext 类型,因为它实现了 IDictionary。