How to store the id and names in arry list using asp.net enter the name Using auto complete ajax tool, so select the name pass the id to db?
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.Co开发者_StackOverflow中文版mmandType = 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
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.
精彩评论