如何使用C#在ASP.NET上添加搜索栏
大家好,我有数据库设置,
1条码有很多商品代码。
i希望创建一个用户输入条形码的搜索栏,并以复选框/子弹形式显示该条形码下的所有项目代码,这样我就可以选择我想要的项目代码以进一步发挥功能。
就像我说的查询和东西我都很好。现在我是如何喜欢文本框,它是执行onclick搜索按钮的输入。
用户标签吗?按钮?提交?他们需要处于某种形式吗?
感谢您的帮助。我看到太多的例子。
我尝试过的事情:
Hi guys, i got the database setup,
1 barcode has many item code.
i want to create a search bar that user enter the barcode and will display all the item code under that barcode in a checkbox/bullet form so i can select which item code i want for futher function.
like i said the query and stuff i am all good. now is how do i like the textbox that is the input to the button that perform onclick for search.
do i user label? button? submit? do they need to be in a form?
Thanks for helping. i am seeing too many example.
What I have tried:
<asp:Label ID="barSearch" runat="server" Text="">Enter Barcode: </asp:Label>
<asp:Button runat="server" ID="btnSearchBar" Style="background-color: #c9302c;" CssClass="btn btn-danger" Text="Search" OnClientClick="javascipt: return confirm('are you sure want to search ?');"CommandArgument='txtSearchString>' CommandName="search" OnClick="btnSearchBar_Click" />
</div>
试试这样
ASPX
try like this
ASPX
<div>
<span>Enter Barcode: </span>
<asp:TextBox runat="server" ID="txtSearch" />
<asp:Button runat="server" ID="btnSearchBar" Style="background-color: #c9302c;" CssClass="btn btn-danger" Text="Search" OnClientClick="javascipt: return confirm('are you sure want to search ?');" OnClick="btnSearchBar_Click" />
<asp:BulletedList ID="bltLstSearchItems" runat="server">
</asp:BulletedList>
</div>
代码背后
Code Behind
protected void btnSearchBar_Click(object sender, EventArgs e)
{
string value = txtSearch.Text.Trim();
// Your Ado.Net code to get data from DB
string[] itemsGotFromDB = { "aaaa", "bbbb", "etc" };
bltLstSearchItems.DataSource = itemsGotFromDB;
bltLstSearchItems.DataBind();
}