 |
BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3
 | This is the forum to discuss the Wrox book Beginning ASP.NET 3.5: In C# and VB by Imar Spaanjaars; ISBN: 9780470187593 |
|
Welcome to the p2p.wrox.com Forums.
You are currently viewing the BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 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
|
|
|
|
|

May 4th, 2011, 10:55 PM
|
|
Registered User
|
|
Join Date: Mar 2011
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Combining FormView and a contact form.
Hi Imar,
I'm trying to combine code from two chapters and come up with a solution.
I have a FormView giving me the results I need, however, I need to take a couple email addresses (that the FormView is providing) then plug those email values into two To.Add statements to send email using the technique described in Chapter 9 (p.308 C# 3.5 or p.317 C# 4, I purchased both of them).
I am having a hard time figuring out how to get those database values. Also, I do not want the values displayed in the URL if I need to pass them to another form page.
Thanks for your time.
Ed T.
Las Vegas, NV.
Last edited by getEd; May 4th, 2011 at 11:01 PM..
|
|

May 5th, 2011, 02:46 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Hi Ed,
Can you describe your scenario in more detail? If you're using Linq to SQL (the 3.5 book) or Entity Framework (used in the 4,0 version) you could get the data out of the database directly, based on some ID. That's probably easier and cleaner than getting it from a FormView.
If you can describe your use case in more detail (e.g. how the user interacts with the site and selects a record), I can supply better guidance.
Thank you, thank you!
Cheers,
Imar
|
|

May 5th, 2011, 01:49 PM
|
|
Registered User
|
|
Join Date: Mar 2011
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
More detail...
Hi Imar,
Looks like I'm using a SqlDataSource over Linq. My database is already on the web and I am using a connection string. Is it advisable I use Linq? I am using Visual Studio 2008 Standard Edition.
Code:
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:PetDataConnectionString %>"
SelectCommand="SELECT * FROM [Table3] WHERE Left(TagID, 18) = @TagID">
<SelectParameters>
<asp:ControlParameter ControlID="txt_IDFind" DefaultValue="-1" Name="TagID"
PropertyName="Text" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
<asp:FormView ID="FormView1" runat="server" DataKeyNames="OwnerID"
DataSourceID="SqlDataSource1" Height="288px" Width="419px">
<ItemTemplate>
Join Date:
<asp:Label ID="JoinDateLabel" runat="server" Text='<%# Eval("JoinDate") %>' />
<br />
<asp:Label ID="TextAddressLabel" runat="server"
Text='<%# Bind("TextAddress") %>' Visible="False" />
<br />
<asp:Label ID="EmailAddressLabel" runat="server"
Text='<%# Bind("EmailAddress") %>' Visible="False" />
<br />
<asp:Image ID="Image1" runat="server" ImageURL='<%# Eval("PicURL") %>' Width = "75%" Height = "75%" ImageAlign="AbsBottom" />
<br />
</ItemTemplate>
</asp:FormView>
From the item template I have a 'join date' visible, and the query also pulls two email addresses (which are hidden), and a picture reference.
Next to the FormView display (which is in the left side of a 3 column table), I have an email contact form set up (columns 2 and 3 of the table) where the current user would put in his contact information. The target address (To.Add) would be the hidden address shown in the code.
I need to take the values currently being hidden from view in the LabelIDs and stick the values in a To.Add. I'm stuck on how make this transition.
I hope this is enough information, if not, let me know.
Thanks,
Ed T.
Las Vegas, NV
|
|

May 7th, 2011, 03:19 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Hi Ed,
I am still not sure how things are to work from an end user's perspective. Can the user select a record from the FormView and use that for the e-mail? Or can they enter new data or update existing data which is then used to send out mail? How is the exact user flow through the application? Not sure, which makes it hard to suggest something concrete, so I'll suggest something vague instead.
1. When inserting or updating the data sing the SqlDataSource control, hook into its events such as Inserting and Updating. Then look at stuff like e.Values or e.NewValues to look at the relevant details the user entered.
2. If you're only displaying data, I would create a LINQ to SQL model or an Entity Framework model, as follows:
a) As explained in the book, create a .dbml or a .edmx file
b) Drag the relevant table on the design surface from the Server Explorer and save
c) In the code behind, query your model with something like this:
Code:
var user = (from p in context.People
where p.Id = someId
select p).First();
EmailAddress.Text = user.EmailAddress;
Obviously, I am just making something up, but it's hard to see what you're doing with something like:
Code:
SELECT * FROM [Table3]
which doesn' really convey any business requirements or business logic... ;-)
Cheers,
Imar
|
|

May 11th, 2011, 01:45 AM
|
|
Registered User
|
|
Join Date: Mar 2011
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Got it!
Hi Imar,
Hey, believe it or not your post helped me (even though my info was vague).
I was able to employ LINQ like you suggested and can see my fields easily now.
Here's a code sample from my button click in case it can help someone else:
Code:
protected void btn_FindAnswer_Click(object sender, EventArgs e)
{
using (DataClassesDataContext myContext = new DataClassesDataContext())
{
var lost = (from a in myContext.Table3s
where a.TagID == txt_FindIDTag.Text
select a).First();
txt_Email.Text = lost.EmailAddress;
}
}
Sincerely,
Ed T.
Las Vegas, NV
|
|

May 11th, 2011, 02:30 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Nice..... Thanks for the update.
Cheers,
Imar
|
Similar Threads
|
| Thread |
Thread Starter |
Forum |
Replies |
Last Post |
| Contact form From Chapter 9 |
susu2009 |
BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 |
3 |
November 20th, 2009 08:49 AM |
| I need help with contact form |
iorgusu |
Need help with your homework? |
1 |
September 27th, 2009 01:56 AM |
| Contact form? |
philthy |
BOOK: ASP.NET MVC Website Programming Problem Design Solution ISBN: 9780470410950 |
1 |
July 23rd, 2009 05:14 PM |
| contact form |
Will |
BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 |
6 |
February 24th, 2009 01:42 PM |
| Contact Form |
myself |
Classic ASP Basics |
1 |
November 18th, 2006 11:16 AM |
|
 |