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?





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

EndSub
</script>
<asp:ContentID="Content1"ContentPlaceHolderID="ContentPlaceHolder1"runat="Server">
<asp:LabelID="lblUserName"runat="server"Text="Label"></asp:Label>
<asp:FormViewID="FormView1"runat="server"DataSourceID="SqlDataSource1"DataKeyNames="UserID">
<ItemTemplate>
UserID:
<asp:LabelID="UserIDLabel"runat="server"Text='<%# Eval("UserID") %>'/>
<br/>
UserName:
<asp:LabelID="UserNameLabel"runat="server"Text='<%# Bind("UserName") %>'/>
<br/>
DisplayName:
<asp:LabelID="DisplayNameLabel"runat="server"Text='<%# Bind("DisplayName") %>'/>
<br/>
FirstName:
<asp:LabelID="FirstNameLabel"runat="server"Text='<%# Bind("FirstName") %>'/>
<br/>
Lastname:
<asp:LabelID="LastnameLabel"runat="server"Text='<%# Bind("Lastname") %>'/>
<br/>
Zip:
<asp:LabelID="ZipLabel"runat="server"Text='<%# Bind("Zip") %>'/>
<br/>
City:
<asp:LabelID="CityLabel"runat="server"Text='<%# Bind("City") %>'/>
<br/>
State:
<asp:LabelID="StateLabel"runat="server"Text='<%# Bind("State") %>'/>
<br/>
PhoneCell:
<asp:LabelID="PhoneCellLabel"runat="server"Text='<%# Bind("PhoneCell") %>'/>
<br/>
PhoneHome:
<asp:LabelID="PhoneHomeLabel"runat="server"Text='<%# Bind("PhoneHome") %>'/>
<br/>
Email:
<asp:LabelID="EmailLabel"runat="server"Text='<%# Bind("Email") %>'/>
<br/>
Pro:
<asp:CheckBoxID="ProCheckBox"runat="server"Checked='<%# Bind("Pro") %>'Enabled="false"/>
<br/>
GeneralApproach:
<asp:LabelID="GeneralApproachLabel"runat="server"Text='<%# Bind("GeneralApproach") %>'/>
<br/>
Rank:
<asp:LabelID="RankLabel"runat="server"Text='<%# Bind("Rank") %>'/>
<br/>
General:
<asp:LabelID="GeneralLabel"runat="server"Text='<%# Bind("General") %>'/>
<br/>
<asp:LinkButtonID="EditButton"runat="server"CausesValidation="True"CommandName="Edit"
Text="Edit User"/>
</ItemTemplate>
</asp:FormView>
<asp:SqlDataSourceID="SqlDataSource1"runat="server"ConnectionString="<%$ ConnectionStrings:steve48ConnectionString %>"
SelectCommand="SELECT * FROM [tblUser] WHERE ([UserName] = @UserName)">
<SelectParameters>
<asp:ControlParameterControlID="lblUserName"Name="UserName"PropertyName="Text"Type="String"/>
</SelectParameters>
</asp:SqlDataSource>
</asp:Content>
 
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
Default

Why not do this?

SqlDataSource:

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

Code:
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

Code:
if (this.PostHelpedYou)
{
   ClickThanksButton(); 
}

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.