如何使用文本框和按钮在datalist中搜索数据。 [英] How to search data in datalist using textbox and button.

查看:99
本文介绍了如何使用文本框和按钮在datalist中搜索数据。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

< asp:DataList ID =   DataList1 runat =   server DataKeyField =  < span class =code-string> ProductID 
DataSourceID = SqlDataSource1 onitemdatabound = 使用 BackColor = 白色
EmptyDataText = 请选择类别。
BorderColor = #E7E7FF BorderStyle = BorderWidth = 1px CellPadding = 3
GridLines = Horizo​​ntal RepeatColumns = 3 RepeatDirection = 水平
高度= 534px宽度= 726px style = text-align:center;颜色:#000000; OnItemCommand = DataList1_ItemCommand >
< AlternatingItemStyle BackColor = 白色 / >
< FooterStyle BackColor = #B5C7DE ForeColor = #4A3C8C />
< HeaderStyle BackColor = #4A3C8C Font-Bold = ForeColor = #F7F7F7 />
< ItemStyle BackColor = 白色 ForeColor = #4A3C8C />
<&的ItemTemplate GT;
< asp:ImageButton ID = btnFileImg runat = server高度= 150px宽度= 100px ImageUrl = ' <%#Eval(filename)%>' PostBackUrl = ' <%#Eval(ProductID,ProductDetails.aspx?ProductID = {0})%>' />
< asp:Label ID = ImageUrlLabel runat = server Text = ' <%#Eval(filename)%>'可见= False > < / asp:Label > < br />
< br />
< a href = ' ProductDetails.aspx?productID =<%#Eval(ProductID) %>' style = font-size:15px; color:black < span class =code-keyword>>
< asp:Label ID = NameLabel runat = server Text = ' <%#Eval(productName)%>' />< br />
< / a >
价格:
< asp:标签ID = PriceLabel runat = server Text = ' <%#Eval(price)%>' />

< / ItemTemplate >
< SelectedItemStyle BackColor = #738A9C字体粗体= True ForeColor = < span class =code-string>#F7F7F7 />
< / asp:DataList >





这是我的文本框和按钮





< asp:TextBox ID =   txtSearch runat =   server >  < /   asp:TextBox  >  
< asp:按钮ID = btnSearch runat = server Text = 搜索 />





这就是我想要做的。 
DATALIST:

产品清单

文本框搜索:Samsung Galaxy S4
当按钮点击datalis显示:

Datalist :
产品编号:2424(< - 示例)
产品名称:Samsung Galaxy S4
描述:Blah blah blah ....
价格:$ 300(< ;-例子)
股票:5(< - 示例)


提前付款

解决方案

300(< - example)
股票:5(< - 示例)


提前致谢




将数据绑定到datalist时,在viewstate中复制数据,然后当用户搜索数据时,从viewstate获取并显示。

<asp:DataList ID="DataList1" runat="server" DataKeyField="ProductID" 
        DataSourceID="SqlDataSource1" onitemdatabound="use" BackColor="White" 
        EmptyDataText="Please Select Category."
           BorderColor="#E7E7FF" BorderStyle="None" BorderWidth="1px" CellPadding="3" 
           GridLines="Horizontal" RepeatColumns="3" RepeatDirection="Horizontal" 
        Height="534px" Width="726px" style="text-align: center; color: #000000;" OnItemCommand="DataList1_ItemCommand">
        <AlternatingItemStyle BackColor="White" />
        <FooterStyle BackColor="#B5C7DE" ForeColor="#4A3C8C" />
        <HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#F7F7F7" />
        <ItemStyle BackColor="White" ForeColor="#4A3C8C" />
         <ItemTemplate>
            <asp:ImageButton ID="btnFileImg" runat="server" Height="150px" Width="100px" ImageUrl='<%# Eval("filename") %>'  PostBackUrl='<%# Eval("ProductID", "ProductDetails.aspx?ProductID={0}") %>' />
            <asp:Label ID="ImageUrlLabel" runat="server" Text='<%# Eval("filename") %>' Visible="False"></asp:Label><br />
    <br />
            <a href='ProductDetails.aspx?productID=<%# Eval("ProductID") %>' style="font-size: 15px; color: black">
            <asp:Label ID="NameLabel" runat="server" Text='<%# Eval("productName") %>'/><br />
            </a>
            Price: 
            <asp:Label ID="PriceLabel" runat="server" Text='<%# Eval("price") %>' />

        </ItemTemplate>
        <SelectedItemStyle BackColor="#738A9C" Font-Bold="True" ForeColor="#F7F7F7" />
    </asp:DataList>



This is my Textbox and Button



<asp:TextBox ID="txtSearch" runat="server"></asp:TextBox>
    <asp:Button ID="btnSearch" runat="server" Text="Search" />



This is what I want to do.
DATALIST:

LIST OF PRODUCTS

Textbox search: Samsung Galaxy S4
When button click datalis shows:

Datalist:
Product ID: 2424(<-- example)
Product Name: Samsung Galaxy S4
Description: Blah blah blah....
Price: $300(<- example)
Stock: 5(<-- example)


Thanks in advance

解决方案

300(<- example) Stock: 5(<-- example) Thanks in advance


Hi,
When you bind the data to datalist, copy the data in viewstate and then when user searches the data, take from the viewstate and display.


这篇关于如何使用文本框和按钮在datalist中搜索数据。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆