0

I'm completely new to web programming. I am using an asp.net Table:
<asp:Table></asp:Table>

and my code behind page (using vb.net)grabs data from a database and displays it in this table.

How do I put in a search that will only display the data with the name that is searched? Do I need to work in the code behind page or the asp page? I'm new to the syntax.

4
Contributors
5
Replies
7
Views
7 Years
Discussion Span
Last Post by MichaelWClark
0

Okay Asp.net is perfect for this exact thing. You will probibly want to use a Gridview and a SQLDataSource to preform this. What I do for my sqldatasource when I need to add basic search functionality is manually edit the select command and add a select parameter:

ex:

<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
            ConnectionString="<%$ ConnectionStrings:MasterSQLConnectionString %>"           
                     
            SelectCommand="SELECT [ThirdPartyName],[ThirdPartyID], [Phone1], [Active] FROM [ThirdParty] WHERE ([ThirdPartyName] Like '%' + @SEARCH +'%') ORDER BY [ThirdPartyName], Active">
            <SelectParameters>
                <asp:ControlParameter ControlID="txtSearch"  DefaultValue="%" 
                    Name="SEARCH" PropertyName="text" />
            </SelectParameters>
        </asp:SqlDataSource>

Then i will tie code to the btnSearch.click that just does a Gridview.Databind(). This will run the Select command again using the search query provided rather than the default value ('%').

So what you need to do:

1. Create SQLDatasource
2. Edit Select Command to include :: WHERE FIELD_NAME LIKE '%' + @SEARCH + '%'
3. Create Gridview/Detailsview/Repeater (gridview offers easy paging and sorting) and tie them to your afformentioned SQLDatasource
4. Create txtSearch (textbox) and btnSearch (button)
5. In your codebhind for btnSearch_click() add Gridview1.DataBind() (orwhatever gridview name is)

This should get your basic functionality up and running.

0

Okay..As you want search functionality, I assume you have a textbox and button and by entering some name in textbox and clicking on button you want to show data for the searched name. right ?

In this case also You can still use <asp:Table> if you want..you just need to modify your existing query which is currently pulling data form database by appending Where condition with some fields/columns on which you want to search entered name..

Again sorting is quite difficult with <asp:Table>. you need to do a some extra coding to achieve sorting within <asp:Table>..

So i suggest go with <asp:GridView>..

Let us know if you encounter any issues.

I'm completely new to web programming. I am using an asp.net Table:
<asp:Table></asp:Table>

and my code behind page (using vb.net)grabs data from a database and displays it in this table.

How do I put in a search that will only display the data with the name that is searched? Do I need to work in the code behind page or the asp page? I'm new to the syntax.

Edited by rohand: n/a

0

o_O I am by no means an 'expert asp.net' programmer. I have learned what I do know on my own and have done very well with that thus far. In my continual reading and researching last night I discovered that my life (and in this case maybe yours) could become much easier and with the use of LINQ to SQL. I suggest checking it out :) there are plenty of tutorials on Google for you to start with.

0

I'm sorry but why take the time to post such a comment? 'I suggest you read a book'...really? Give a title, an author...something... a link? Without any further information Cynix that post is just taking up space. IMHO.

http://www.onlinecomputerbooks.com/free-asp.net-books.php
http://aspnet.4guysfromrolla.com/2.0/
http://msdn.microsoft.com/en-us/aa336522.aspx

http://www.amazon.com/Sams-Teach-Yourself-ASP-NET-Days/dp/0672321688
http://www.amazon.com/Beginning-ASP-NET-3-5-VB-Programmer/dp/047018759X/ref=pd_cp_b_1

4.0 to 3.5 is not going to make or break your ability to program. Just find a good resource that fits with your learning style and run with it.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.