Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 3.5 > ASP.NET 3.5 Basics
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
ASP.NET 3.5 Basics If you are new to ASP or ASP.NET programming with version 3.5, this is the forum to begin asking questions. Please also see the Visual Web Developer 2008 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 3.5 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
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 22nd, 2010, 06:24 PM
Authorized User
 
Join Date: Jun 2003
Location: , , .
Posts: 54
Thanks: 1
Thanked 0 Times in 0 Posts
Default Detailsview Not Visible -Help Please

I have a details view that is supposed to display one record from a master gridview on another page. I had this working but "broke" it.I am binding the detailsview programmatically to datareader. There are no errors but the Detailsview is not visible.If I eamine the data from the data reader it is correct.

<%@ Page Title="" Language="vb"
AutoEventWireup="true" MasterPageFile="~/boost.master"%>
<script runat="server">

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

If IsPostBack = False Then
lblIssues.Text = "Select up to 5 issues"
lblIssues.ForeColor = Drawing.Color.Black
PopulateDetailsView()
End If
End Sub
Protected Sub PopulateDetailsView()
Dim Conn As New SqlConnection(SqlDataSource1.ConnectionString)
Dim objDR As SqlDataReader
Dim Cmd1 As New SqlCommand("procGetAdByIdSelect", Conn)
Dim AdId As Integer
Dim Email, FName, Headline, Adtext, URL, Searchterm, ProdSvce As String
Dim Issue1, Issue2, Issue3, Issue4, Issue5 As String
Cmd1.CommandType = Data.CommandType.StoredProcedure
Cmd1.Parameters.AddWithValue("@adid", Session("adid"))

Conn.Open()

objDR = Cmd1.ExecuteReader(System.Data.CommandBehavior.Clo seConnection)
If objDR.HasRows Then
While objDR.Read
AdId = CType(objDR("adid"), Integer)
Email = CType(objDR("Email"), String)
FName = CType(objDR("FName"), String)
Headline = CType(objDR("Headline"), String)
Adtext = CType(objDR("Adtext"), String)
URL = CType(objDR("URL"), String)
Searchterm = CType(objDR("Searchterm"), String)
ProdSvce = CType(objDR("ProdSvce"), String)
Issue1 = CType(objDR("Issue1"), String)
Issue2 = CType(objDR("Issue2"), String)
Issue3 = CType(objDR("Issue3"), String)
Issue4 = CType(objDR("Issue4"), String)
Issue5 = CType(objDR("Issue5"), String)


End While

End If

DetailsView1.DataSource = objDR
DetailsView1.DataBind()

DetailsView1.Visible = "True"
objDR.Close()
Conn.Close()
End Sub
Protected Sub SendMessage()
Dim whosent As String

whosent = "david@boostctr.com"
Dim Conn As New SqlConnection(dsEmail.ConnectionString)
Dim recipient As String
Dim mailServerName As String = "Mail.boostctr.com"
Dim mailClient As SmtpClient = New SmtpClient
Dim basicAuthenticationInfo As New System.Net.NetworkCredential("xxxxxxcom", "xxxxxx")
Dim message As MailMessage
Dim MediaType As String = "text/html"

mailClient.Host = "mail.boostctr.com"
mailClient.UseDefaultCredentials = False
mailClient.Credentials = basicAuthenticationInfo


recipient = "tbd"
message = New System.Net.Mail.MailMessage(whosent, recipient)
message.Subject = "tbd"


End Sub





Protected Sub btnSendEmail_Click(ByVal sender As Object, ByVal e As System.EventArgs)
SendMessage()
End Sub

Protected Sub CheckBoxListIssues_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)

Dim ItemsSelectedCount As Integer
ItemsSelectedCount = 0

For Each LItems As ListItem In CheckBoxListIssues.Items
If LItems.Selected = True Then
ItemsSelectedCount = ItemsSelectedCount + 1
End If
Next
Session("TooManyIssues") = False
If ItemsSelectedCount > 5 Then Session("TooManyIssues") = "True"
If Session("TooManyIssues") = "True" Then
lblIssues.Text = "Only 5 Issues Allowed"
lblIssues.ForeColor = Drawing.Color.Red
Else
lblIssues.Text = "Select up to 5 issues"
lblIssues.ForeColor = Drawing.Color.Black
End If
End Sub

Protected Sub btnApplyIssues_Click(ByVal sender As Object, ByVal e As System.EventArgs)
If Session("TooManyIssues") = "True" Then
lblIssues.Text = "Only 5 Issues Allowed"
lblIssues.ForeColor = Drawing.Color.Red
Exit Sub
Else
lblIssues.Text = "Select up to 5 issues"
lblIssues.ForeColor = Drawing.Color.Black
End If

End Sub
</script>



<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">

<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:steve48ConnectionString %>">

</asp:SqlDataSource>

<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>

<div>


<asp:DetailsView ID="DetailsView1" runat="server"
AutoGenerateRows="False" CssClass="detailsview">
<Fields>
<asp:BoundField DataField="AdID" HeaderText="AdID" InsertVisible="False"
ReadOnly="True" SortExpression="AdID" />
<asp:BoundField DataField="EMail" HeaderText="EMail" SortExpression="EMail" />
<asp:BoundField DataField="FName" HeaderText="FName" SortExpression="FName" />
<asp:BoundField DataField="Headline" HeaderText="Headline"
SortExpression="Headline" />
<asp:BoundField DataField="Adtext" HeaderText="Adtext"
SortExpression="Adtext" />
<asp:BoundField DataField="URL" HeaderText="URL" SortExpression="URL" />
<asp:BoundField DataField="Searchterm" HeaderText="Searchterm"
SortExpression="Searchterm" />
<asp:BoundField DataField="ProdSvce" HeaderText="ProdSvce"
SortExpression="ProdSvce" />
<asp:BoundField DataField="Issue1" HeaderText="Issue1"
SortExpression="Issue1" />
<asp:BoundField DataField="Issue2" HeaderText="Issue2"
SortExpression="Issue2" />
<asp:BoundField DataField="Issue3" HeaderText="Issue3"
SortExpression="Issue3" />
<asp:BoundField DataField="Issue4" HeaderText="Issue4"
SortExpression="Issue4" />
<asp:BoundField DataField="Issue5" HeaderText="Issue5"
SortExpression="Issue5" />
<asp:CheckBoxField DataField="Active" HeaderText="Active"
SortExpression="Active" />
<asp:BoundField DataField="ReviewerID" HeaderText="ReviewerID"
SortExpression="ReviewerID" />

</Fields>

</asp:DetailsView>



<div style="text-align:center;">
<asp:Button ID="btnSendEmail" runat="server" Text="Send Email" onclick="btnSendEmail_Click"
class="button"/>

<br />

</div>
<div >
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>
<div style="text-align:center;">
<asp:Label ID="lblIssues" runat="server" Text="" ForeColor="#CC3300"></asp:Label>
</div>
<asp:CheckBoxList class="tablecenter" ID="CheckBoxListIssues" runat="server" AutoPostBack="True"
TextAlign="Right" style="position: relative" OnSelectedIndexChanged="CheckBoxListIssues_Selecte dIndexChanged">
<asp:ListItem>Stronger Call To Action</asp:ListItem>
<asp:ListItem>Punctuation</asp:ListItem>
<asp:ListItem>Awkward Grammar</asp:ListItem>
<asp:ListItem>Use Caps In The Display URL</asp:ListItem>
<asp:ListItem>No Product Benefit</asp:ListItem>
<asp:ListItem>No Product Features</asp:ListItem>
<asp:ListItem>Stronger Call To Action</asp:ListItem>
<asp:ListItem>Differentiate From Competitors</asp:ListItem>
<asp:ListItem>Repeating Words</asp:ListItem>
<asp:ListItem>Keywords Not in Title</asp:ListItem>
<asp:ListItem>Lack of Brand Recognition</asp:ListItem>
</asp:CheckBoxList>
<div style="text-align:center;">
<asp:Button ID="btnApplyIssues" runat="server" Text="Apply Issues" onclick="btnApplyIssues_Click"
class="button"/>

<br />
</div>
</ContentTemplate>
</asp:UpdatePanel>
</div>


</div>
<asp:SqlDataSource ID="dsEmail" runat="server">

</asp:SqlDataSource>

</asp:Content>

Last edited by sg48; March 22nd, 2010 at 06:58 PM..
  #2 (permalink)  
Old March 25th, 2010, 06:25 AM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

Take a look at this:

Code:
 
If objDR.HasRows Then
  While objDR.Read
    AdId = CType(objDR("adid"), Integer)
    Email = CType(objDR("Email"), String)
    ...
  End While
End If

DetailsView1.DataSource = objDR
You're using the reader to fill your local variables. A reader can only be read once. So, after you're done reading the fields into your own variables, the reader is "empty". If you then bind it to the DetaislView, you get nothing....

Hope this helps,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
  #3 (permalink)  
Old March 25th, 2010, 07:33 AM
Authorized User
 
Join Date: Jun 2003
Location: , , .
Posts: 54
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Makes sense. I switched to a dataset and problem is solved. Thank you.
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Visible GridView jezywrap ASP.NET 2.0 Basics 3 March 20th, 2007 01:07 PM
visible/invisible stealthdevil Access VBA 4 December 1st, 2006 05:40 PM
image not visible somsahi Struts 2 July 27th, 2006 02:25 PM
Panel.visible shai505 C# 1 April 25th, 2006 05:10 AM
visible vs. not visible on form akibaMaila VB.NET 2002/2003 Basics 2 August 15th, 2005 02:40 PM



All times are GMT -4. The time now is 05:47 PM.


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