 |
BOOK: Beginning ASP.NET 4 : in C# and VB
 | This is the forum to discuss the Wrox book Beginning ASP.NET 4: in C# and VB by Imar Spaanjaars; ISBN: 9780470502211 |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the BOOK: Beginning ASP.NET 4 : in C# and VB section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|
|

November 23rd, 2011, 03:36 PM
|
|
Authorized User
|
|
Join Date: Oct 2010
Posts: 71
Thanks: 12
Thanked 0 Times in 0 Posts
|
|
Text box, button and data retrieval
Hi all,
I have a webform page in aspx and have a text box and a button on the page. I want a user to be able to enter a name and press the button, for the control to search a database and then return the results in a gridview or DetailsView.
However, I can't find anywhere that shows me the code... In the book it shows you how to get the control to post the text box content to a label, but nothing more!
Please help!
Regards
Lee
|
|

November 23rd, 2011, 04:15 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
You can use LINQ to EF to query the database and then bind the results to a Grid. E.g. (untested, pseudo code only)
Code:
var someStuff = from s in SomeStuff where s.Name.StartsWith(textBox1.Text). select s;
myGrid.DataSource = someStuff;
myGrid.DataBind();
Hope this helps,
Imar
|
|

November 23rd, 2011, 04:21 PM
|
|
Authorized User
|
|
Join Date: Oct 2010
Posts: 71
Thanks: 12
Thanked 0 Times in 0 Posts
|
|
And this code would go into the aspx page not the code behind?
My markup is below:
Code:
<%@ Page Title="" Language="VB" MasterPageFile="~/Site.master" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="ManagementTest_Default" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server">
<p>Search for a client by name:</p>
<p>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" />
</p>
<p>
Or please select a condition from the dropdown list below:</p>
|
|

November 23rd, 2011, 04:32 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
It would go in the Code Behind, in the Button's Click handler to be precise....
Imar
|
|

November 23rd, 2011, 06:13 PM
|
|
Authorized User
|
|
Join Date: Oct 2010
Posts: 71
Thanks: 12
Thanked 0 Times in 0 Posts
|
|
Thanks Imar.
Could you expand on the code you gave me earlier?
Regards
Lee
|
|

November 23rd, 2011, 06:26 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
What would you like me to expand on? It's similar to some other stuff in the book. Remember the Repeater in the Review pages? This is exactly the same concept.
Cheers,
Imar
|
|

November 23rd, 2011, 06:37 PM
|
|
Authorized User
|
|
Join Date: Oct 2010
Posts: 71
Thanks: 12
Thanked 0 Times in 0 Posts
|
|
What part of the code are needing me to replace with my own elements and what need to stay as yo wrote them? I know that this needs testing as you said it was untested!
Like SomeStuff.... select s.... StartsWIth.....
Code:
var someStuff = from s in SomeStuff where s.Name.StartsWith(textBox1.Text). select s;
myGrid.DataSource = someStuff;
myGrid.DataBind();
I'll also re-read the stuff on repeaters...
Thanks.
|
|

November 24th, 2011, 04:11 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
The first line is a custom query which you need to replace with your own. Again, take a look at the Code Behind of the varous Reviews pages to see examples.
Cheers,
Imar
|
|
 |
|