如何使用asp.net将id和名称存储在arry列表中输入名称使用自动完成ajax工具,因此选择名称将id传递给db?
我正在使用 Asp.net、C#.net 和 sql server。我的问题是用户在文本框中输入名称,自动滚动名称(我在 ajax 和 Web 服务中使用自动完成工具),但名称仅显示但我已经选择了通过数据库传递的名称特定 ID在存储目的中,我如何使用列表仅获取名称,任何人都可以帮助我 我的代码是 Autocomplete.asmx页面
[WebMethod]
public string[] GetCompletionList(string prefixText, int count)
{
if (count == 0)
{
count = 10;
}
DataTable dt = GetRecords(prefixText);
List<string> items = new List<string>(count);
for (int i = 0; i < dt.Rows.Count; i++)
{
string strName = dt.Rows[i][0].ToString();
items.Add(strName);
}
return items.ToArray();
}
public DataTable GetRecords(string strName)
{
SqlCommand cmd = new SqlCommand("Usp_Consultant", LITRMSConnection);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@consultantname", strName);
DataSet objDs = new DataSet();
SqlDataAdapter dAdapter = new SqlDataAdapter();
dAdapter.SelectCommand = cmd;
LITRMSConnection.Open();
dAdapter.Fill(objDs);
LITRMSConnection.Close();
return objDs.Tables[0];
}
存储过程是
CREATE Procedure Usp_Consultant
(@consultantname varchar(100))
As
Begin
select (FirstName+LastName)as ConsultantName from Consultant where FirstName like '%'+@consultantname+'%'
union all
select(Firstname+LastName)as consultantName from InDirectConsultant i where FirstName like '%'+@consultantname+'%'
ORDER BY 1;
End
但我也有这样的id
select Consid, (FirstName+LastName)as ConsultantName from Consultant where FirstName like '%'+@consultantname+'%'
Consid是Varchar。
谢谢你 赫曼斯
I am using Asp.net, C#.net and sql server. my Issue is user enter the name in textbox automatically scrolling the name (i am using Autocomplete tool in ajax and web services) but names only display but i have select the name particular id pass the database in storing purpose , how it possible i am using list get the names only any one help me
my code is
Autocomplete.asmx page
[WebMethod]
public string[] GetCompletionList(string prefixText, int count)
{
if (count == 0)
{
count = 10;
}
DataTable dt = GetRecords(prefixText);
List<string> items = new List<string>(count);
for (int i = 0; i < dt.Rows.Count; i++)
{
string strName = dt.Rows[i][0].ToString();
items.Add(strName);
}
return items.ToArray();
}
public DataTable GetRecords(string strName)
{
SqlCommand cmd = new SqlCommand("Usp_Consultant", LITRMSConnection);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@consultantname", strName);
DataSet objDs = new DataSet();
SqlDataAdapter dAdapter = new SqlDataAdapter();
dAdapter.SelectCommand = cmd;
LITRMSConnection.Open();
dAdapter.Fill(objDs);
LITRMSConnection.Close();
return objDs.Tables[0];
}
Stored procedure is
CREATE Procedure Usp_Consultant
(@consultantname varchar(100))
As
Begin
select (FirstName+LastName)as ConsultantName from Consultant where FirstName like '%'+@consultantname+'%'
union all
select(Firstname+LastName)as consultantName from InDirectConsultant i where FirstName like '%'+@consultantname+'%'
ORDER BY 1;
End
but i have id also like this
select Consid, (FirstName+LastName)as ConsultantName from Consultant where FirstName like '%'+@consultantname+'%'
Consid is Varchar.
Thank u
hemanth
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该从 Web 服务返回一个包含名称和 ID 的 json 对象,当用户选择名称时,使用 autocompleteselect 事件获取 ID 并将其放入页面上的隐藏字段中。
当您回发页面时,您将获得此 ID。
You should return a json object back from your webservivce that includes the name and the ID, and when the user selects the name, using the autocompleteselect event, grab the ID and put it in a hidden field on the page.
You will then have this ID when you post back the page.