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 March 31st, 2009, 09:37 PM
Authorized User
 
Join Date: Jan 2009
Posts: 23
Thanks: 8
Thanked 0 Times in 0 Posts
Default GridView Databind issue

Hello pple, sorry for the long chunk of codes.

What i am trying to do over here is, ViewAllMessages will display all the messages of a particular user, and ViewMessage will display the message content, determined by title.

The problem over here is, whenever i click on the title, it will display all the messages, not just the particular message title contents.
What exactly is the problem over here?

Code for ViewAllMessages.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ViewAllMessages.aspx.cs" Inherits="ViewPersonalMessages" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" BorderStyle="None"
GridLines="None" Visible="true" Width="443px">
<Columns>
<asp:TemplateField>
<ItemTemplate>
&nbsp; &nbsp;&nbsp;<br />
<table style="width: 353px; height: 96px">
<tr>
<td style="width: 54px">
<asp:Label ID="lblFrom" runat="server" Text="From:" Font-Bold="True"></asp:Label></td>
<td colspan="2">
<a href="<%# Eval("Email", "ProfilePage.aspx?Email={0}") %>">
<asp:Image ID="imgPP" runat="server" Height="50" ImageUrl='<%# Eval("UID", "testingGetImg.aspx?UID={0}") %>' Width="50" />
<br />
<asp:Label ID="Label1" runat="server" Font-Bold="True" Font-Underline="True" Text='<%# Bind("FullName") %>' Font-Size="Smaller"></asp:Label></a></td>
</tr>
<tr>
<td style="width: 54px; height: 22px">
<asp:Label ID="lblDate" runat="server" Text="Date:" Font-Bold="True"></asp:Label></td>
<td colspan="2" style="height: 22px">
<asp:Label ID="datetime" runat="server" ForeColor="#C00000" Text='<%# Bind("SystemDate") %>'></asp:Label></td>
</tr>
<tr>
<td style="width: 54px; height: 21px">
<asp:Label ID="lblTitle" runat="server" Text="Title:" Font-Bold="True"></asp:Label></td>
<td colspan="2" style="height: 21px">
<asp:Label ID="lblRetrieveTitle" runat="server" Text='<%# Bind("Title") %>'></asp:Label></td>
</tr>
<tr>
<td style="width: 54px; height: 21px">
<asp:Label ID="lblMessage" runat="server" Text="Message:" Font-Bold="True"></asp:Label></td>
<td colspan="2" style="height: 21px">
<asp:Label ID="lblRetrieveMessage" runat="server" Text='<%# Bind("TextInput") %>'></asp:Label></td>
</tr>
</table>
<hr />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp;
</div>
</form>
</body>
</html>

Code for ViewAllMessages.cs
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class ViewAllMessages : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string strConString = ConfigurationManager.ConnectionStrings["SocialSystemConnectionString"].ConnectionString;
SqlConnection con = new SqlConnection(strConString);
SqlCommand cmd = new SqlCommand("SELECT DISTINCT [User].UID, [User].FullName, [Message].SystemDate, [Message].Title, [Message].TextInput, [Message].Email FROM [User] INNER JOIN [Message] ON [User].Email = [Message].Email", con);
con.Open();
SqlDataReader reader = cmd.ExecuteReader();
GridView1.DataSource = reader;
GridView1.DataBind();
reader.Close();
con.Close();
}
}



Code for ViewMessage.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ViewMessage.aspx.cs" Inherits="ViewMessage" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" BackColor="#CCCCCC"
BorderColor="#999999" BorderStyle="Solid" BorderWidth="3px" CellPadding="0" DataSourceID="MessageDataSource"
ForeColor="Black" Height="187px" Width="562px">
<FooterStyle BackColor="#CCCCCC" />
<RowStyle BackColor="White" />
<Columns>
<asp:TemplateField HeaderText="From" SortExpression="Email">

<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("Email") %>'></asp:Label>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Title" SortExpression="Title">

<ItemTemplate>
<a href="<%# Eval("Title", "ViewPersonalMessages.aspx?Title={0}") %>">
<asp:Label ID="Label2" runat="server" Text='<%# Bind("Title") %>'></asp:Label></a>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Date" SortExpression="SystemDate">

<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Bind("SystemDate") %>'></asp:Label>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Status" SortExpression="Status">

<ItemTemplate>
<asp:Label ID="Label4" runat="server" Text='<%# Bind("Status") %>'></asp:Label>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
</asp:TemplateField>
</Columns>
<PagerStyle BackColor="#CCCCCC" ForeColor="Black" HorizontalAlign="Left" />
<SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="Black" BorderStyle="Dashed" Font-Bold="True" ForeColor="White" />
<EditRowStyle BorderStyle="Dotted" HorizontalAlign="Center" VerticalAlign="Middle" />
</asp:GridView>
<br />
<asp:SqlDataSource ID="MessageDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:SocialSystemConnectionString %>"
SelectCommand="SELECT [Email], [Title], [SystemDate], [Status] FROM [Message]"></asp:SqlDataSource>
</div>
</form>
</body>
</html>
 
Old March 31st, 2009, 11:05 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Couple of things I see:

1. In view all messages, the only thing that is clickable in the form of a link is the href to the profile page, i don't see a link anywhere to ViewMessage?

2. On the View Message you are using this query in your sql datasource: SELECT [email], [Title], [SystemDate], [Status] FROM [Message] obviously this is going to return all of the data from your table since you have not supplied a WHERE clause (probably where ID = n I would imagine).

I think if you add a where clause to your query it will help you clear things up.

http://msdn.microsoft.com/en-us/library/z72eefad.aspx

hth.
-Doug
__________________
===============================================
Doug Parsons
Wrox online library: Wrox Books 24 x 7
Did someone here help you? Click on their post!
"Easy is the path to wisdom for those not blinded by themselves."
===============================================





Similar Threads
Thread Thread Starter Forum Replies Last Post
Gridview, databind retrieving value from database julius ASP.NET 2.0 Basics 1 March 23rd, 2009 11:33 PM
Databind a gridview question. chobo2 ASP.NET 3.5 Basics 4 March 8th, 2009 04:38 PM
DataView will not DataBind with a GridView?! jason.l ASP.NET 2.0 Basics 0 October 13th, 2006 10:01 PM
Gridview Update Issue jpgregg ASP.NET 2.0 Professional 0 September 1st, 2006 07:35 PM
Gridview DataBind to DataTable not showing changes wirerider ASP.NET 2.0 Basics 1 March 4th, 2006 08:59 PM





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