Hi All
[System.Web.Script.Services.ScriptMethod()]
[System.Web.Services.WebMethod]
publicstaticList<string> GetCompletionList(stringprefixText, intcount)
{
using(OracleConnection con = newOracleConnection("data source=localhost:1521/orcl; user id=alhakimy; password=alhakimyyes;"))
{
using(OracleCommand com = newOracleCommand())
{
com.CommandText ="select doc_no, doc_name from doctors where city_no= Session['city_no'] and doc_name like '%"+ prefixText + "%' ";
com.Parameters.Add("@TextBox1", prefixText);
com.Connection = con;
con.Open();
List<string> summ =newList<string>();
using(OracleDataReader sdr = com.ExecuteReader())
{
while(sdr.Read())
{
summ.Add(string.Format("{0}-{1}",
sdr["DOC_NAME"], sdr["Doc_NO"]));
}
}
con.Close();
returnsumm;
}
}
}
In the previous codeI have an autocomplete list that shows the (doc_no,doc_name)
The result is the appearance of the doctor's name and number in the textbox1
Now I only want to insert the doc_no and leave the doc_name in database
I used this code
("insert into daily_do (MAN_NO,date_ee,DOC_NO,TIME_V,DA_NO,fail_vis) VALUES ('"+ lblman_no.Text + "', to_date('"+ txtdate.Text + "12:00:00','YYYY-MM-DD HH:MI:ss') ,'"+ textbox1.text + "','"+ DropDownList1.SelectedValue + "',(select max(DA_NO) from daily_do)+1,'"+ DropDownList2.SelectedValue + "')", connect);
I used this code for solutionAfter adding a hidden field and a button
<script type="text/javascript">
$(function() {
$("[id$=textbox1]").autocomplete({
source: function(request, response) {
$.ajax({
url:'<%=ResolveUrl("~/daily.aspx/GetCompletionList") %>',
data:"{ 'prefixtext': '"+ request.term + "'}",
dataType:"json",
type:"POST",
contentType:"application/json; charset=utf-8",
success:function(data) {
response($.map(data.d,function(item) {
return{
label: item.split('-')[0],
val: item.split('-')[1]
}
}))
},
error:function(response) {
alert(response.responseText);
},
failure:function(response) {
alert(response.responseText);
}
});
},
select: function(e, i) {
$("[id$=hfdoc_no]").val(i.item.val);
},
minLength: 1
});
});
</script>
===============================================
<asp:TextBox ID="TextBox1"runat="server"Height="30px"style="font-size: large; font-weight: 700"Width="235px"autocomplete="off"></asp:TextBox>
<asp:Button ID="submit"runat="server"OnClick="Submit"Text="sub"
/>
<asp:HiddenField ID="hfdoc_no"runat="server"/>
===============================================
protectedvoidSubmit(objectsender, EventArgs e)
{
stringdoc_name = Request.Form[TextBox1.UniqueID];
stringdoc_no = Request.Form[hfdoc_no.UniqueID];
ClientScript.RegisterStartupScript(this.GetType(),"alert", "alert('Name: "+ doc_name +"\\nNO: "+ doc_no +"');", true);
}
==============================================
But the doc_no does not pass to the hidden field and the result is the appearance of message box in which the following is written
Name:mohammed-2458
NO:
While the result is supposed to be as follows
Name: mohammed
NO: 2458