像下拉列表一样绑定文本框 [英] bind textbox like dropdownlist
问题描述
我是否可以像dropdownlist那样绑定文本框,这意味着在dropdownlist中,我们可以设置datatextfield以显示文本,而datavaluefield可以将值插入数据库.
我必须使用文本框,我已经向文本框添加了自动完成ajax工具包扩展程序.我只显示学生姓名,但单击按钮后,我必须在数据库中插入学生的SID,而不是学生姓名.我在Google上搜索谷歌,他们告诉我使用自动填充扩展程序的OnClientItemSelected.
Can I bind textbox like dropdownlist means in dropdownlist we can set datatextfield to show text and datavaluefield to insert value into database.
I have to do using textbox,I have added Autocomplete ajax toolkit extender to textbox. I am showing only Student Names but on click of button i have to insert SID of student not student name into the database.I search google they tell me use OnClientItemSelected of Autocomplete extender.How can i do any idea regarding this.
[System.Web.Services.WebMethodAttribute(), System.Web.Script.Services.ScriptMethodAttribute()]
public static string[] Getdata(string prefixText, int count, string contextKey)
{
strSQL = "SELECT SID,Student_Name FROM Student_Master WHERE Student_Name Like '" + prefixText + "%'";
DataTable dataTablePatient_Master = null;
dataTablePatient_Master = objSqlDbComm.ExecuteDatasetQuery(strSQL).Tables[0];
List<String> list = new List<String>();
foreach(DataRow dr in dataTablePatient_Master.Rows)
{
list.Add(dr["Student_Name"].ToString());
}
return list.ToArray();
}
<asp:TextBox ID="txtStudentName" AutoCompleteType="Disabled" CssClass="csstextbox"
runat="server"></asp:TextBox>
<asp:AutoCompleteExtender ID="txtStudentName_AutoCompleteExtender" runat="server"
ServiceMethod="Getdata" OnClientItemSelected="OnItemSelected" CompletionListCssClass="cssautocompletetextbox" MinimumPrefixLength="1"
CompletionInterval="1000" EnableCaching="true" CompletionSetCount="1" TargetControlID="txtStudentName"
UseContextKey="True">
</asp:AutoCompleteExtender>
推荐答案
^ ]
i找到了一些有关文本框绑定的好链接
http://www.daniweb.com/web-development/aspnet/threads/39519/how-to-databind-to-文本框 [ http://stackoverflow.com/问题/4939849/bind-a-text-box-to-a-field-selected-by-sqldatasource-vb-net [
i found some good link regarding Textbox binding
http://www.daniweb.com/web-development/aspnet/threads/39519/how-to-databind-to-textboxes[^]
http://stackoverflow.com/questions/4939849/bind-a-text-box-to-a-field-selected-by-sqldatasource-vb-net[^]
根据需要尝试运行的项目
使用AutoComplete扩展器自动执行回发 [ ^ ]
如果得到答案,请标记解决方案.
谢谢
ashish
try the running project for your requirement
Using the AutoComplete Extender to Automatically Perform a PostBack[^]
mark solution if you get your answer.
Thanks
ashish
这篇关于像下拉列表一样绑定文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!