Wrox Programmer Forums
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics 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
Old December 13th, 2008, 07:34 PM
Authorized User
Join Date: Jun 2003
Posts: 54
Thanks: 1
Thanked 0 Times in 0 Posts
Default FormView Not Displaying Data

I have a page with a label control at top. On Page Load I am setting the lable text to User.Identity.Name. This user name is also stored in my tblUserTable in the UserName Column.. To simplify things, I have a formview with only an item template. In my SELECT command, if I eliminate the WHERE clause, the first record is displayed. If I put in the WHERE clause as shown below, the data is not displayed. Any thoughts?

<%@PageLanguage="VB"MasterPageFile="~/bridgewho.master"Title="My Profile" %>
ProtectedSub Page_Load(ByVal sender AsObject, ByVal e As System.EventArgs)
lblUserName.Text = "User Name: " & User.Identity.Name

<asp:LabelID="UserIDLabel"runat="server"Text='<%# Eval("UserID") %>'/>
<asp:LabelID="UserNameLabel"runat="server"Text='<%# Bind("UserName") %>'/>
<asp:LabelID="DisplayNameLabel"runat="server"Text='<%# Bind("DisplayName") %>'/>
<asp:LabelID="FirstNameLabel"runat="server"Text='<%# Bind("FirstName") %>'/>
<asp:LabelID="LastnameLabel"runat="server"Text='<%# Bind("Lastname") %>'/>
<asp:LabelID="ZipLabel"runat="server"Text='<%# Bind("Zip") %>'/>
<asp:LabelID="CityLabel"runat="server"Text='<%# Bind("City") %>'/>
<asp:LabelID="StateLabel"runat="server"Text='<%# Bind("State") %>'/>
<asp:LabelID="PhoneCellLabel"runat="server"Text='<%# Bind("PhoneCell") %>'/>
<asp:LabelID="PhoneHomeLabel"runat="server"Text='<%# Bind("PhoneHome") %>'/>
<asp:LabelID="EmailLabel"runat="server"Text='<%# Bind("Email") %>'/>
<asp:CheckBoxID="ProCheckBox"runat="server"Checked='<%# Bind("Pro") %>'Enabled="false"/>
<asp:LabelID="GeneralApproachLabel"runat="server"Text='<%# Bind("GeneralApproach") %>'/>
<asp:LabelID="RankLabel"runat="server"Text='<%# Bind("Rank") %>'/>
<asp:LabelID="GeneralLabel"runat="server"Text='<%# Bind("General") %>'/>
Text="Edit User"/>
<asp:SqlDataSourceID="SqlDataSource1"runat="server"ConnectionString="<%$ ConnectionStrings:steve48ConnectionString %>"
SelectCommand="SELECT * FROM [tblUser] WHERE ([UserName] = @UserName)">
Old December 14th, 2008, 02:28 AM
Lee Dumond's Avatar
Wrox Author
Join Date: Jan 2008
Posts: 923
Thanks: 12
Thanked 166 Times in 162 Posts

Why not do this?


<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
          ConnectionString="<%$ ConnectionStrings:steve48ConnectionString %>"
          SelectCommand="SELECT * FROM [tblUser] WHERE ([UserName] = @UserName)">
             <asp:Parameter Name="UserName" Type="String" />
Then, set the value of the parameter in the Selecting event:

Protected Sub SqlDataSource1_Selecting(ByVal sender As Object, _
   ByVal e As System.Web.UI.WebControls.SqlDataSourceSelectingEventArgs) _
   Handles SqlDataSource1.Selecting

   e.Command.Parameters("@UserName").Value = User.Identity.Name

End Sub
Visit my blog at http://leedumond.com
Follow me on Twitter: http://twitter.com/LeeDumond

if (this.PostHelpedYou)

Last edited by Lee Dumond; December 14th, 2008 at 02:31 AM..
Old December 14th, 2008, 12:06 PM
Authorized User
Join Date: Jun 2003
Posts: 54
Thanks: 1
Thanked 0 Times in 0 Posts
Default Thank you

Thank you. That worked and it was a big help.- Steve

Similar Threads
Thread Thread Starter Forum Replies Last Post
Trouble displaying DetailsView & FormView Sheri B ASP.NET 2.0 Basics 0 November 11th, 2006 04:08 PM
Capture and emaio formview control data nuttylife2 ASP.NET 1.x and 2.0 Application Design 0 August 1st, 2006 11:44 AM
Displaying My Data jamil umar ASP.NET 2.0 Basics 0 June 5th, 2006 09:48 AM
Help! Retrieving data from a formview!?! FabRed VB Databases Basics 0 April 23rd, 2006 09:39 AM
data from query not displaying -Dman100- Classic ASP Professional 8 July 19th, 2004 02:23 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.