|
| Re: Show from database with a specific ID? |
 |
Wed, 19 Mar 2008 15:02:18 +000 |
Your database should have an ID field for each record. If it does not, add an
integer column for it, set it as the primary key, and to auto-increment.
As for the ASP.NET side of things, it appears to me you're doing a LOT more
work than you need to be doing. Do you have a seperate ASPX and ASPX.cs page
for every letter of the alphabet? That's waaaaaaay more code than you need. I
would create a single page called ViewRecords.aspx that takes arguments from the
query string to determin which SQL it should run. In the case where you want to
display just a single record, you would go to ViewRecord.aspx?ID=123 (or
whatever the record ID is). When the page is loaded, if "ID" is found
in the query string, then update your SQL to query for only that ID.
ViewRecord.aspx would also have a form with fields on it which you can use to
search by artist, record, or any other fields you want to search on. Submitting
that form would cause the dynamic SQL to be built (with appropriate LIKE
statements).
|
| Post Reply
|
| Re: Show from database with a specific ID? |
 |
Wed, 19 Mar 2008 15:17:28 +000 |
Hello dprior!
Yes i have an ID for each record with Int(11), not null, auto_increment.
As i'm new to asp.net i have big troubles to understand. I'm more familiar with
the old classic asp.
What you are explaining is ofcourse possible to do (because you write so ;) but
i just don't understand how to write it.....
The problem is still how to view a single record.
Thank you very much for writing!
Best regards
Johan
|
| Post Reply
|
| Show from database with a specific ID? |
 |
Wed, 19 Mar 2008 16:10:06 +000 |
Hi!
Working on a project where i can show my vinyl records. My problem is that i
don't know how to show a specific record? I can show records by letter/all and
so on. But not a single one!
For example i show records under letter "T" with following code:
<%@ Page Language="C#"
MasterPageFile="~/MasterPage.master" AutoEventWireup="true"
CodeFile="t.aspx.cs" Inherits="_LetterT" Title="Bocken
Records :: Collecting records :: Records" %>
<asp:Content ID="Content2"
ContentPlaceHolderID="ContentPlaceHolder2"
Runat="Server">
<div class="content_inc_header">
SORT BY LETTER "T"
</div>
</asp:Content>
<asp:Content ID="Content1"
ContentPlaceHolderID="ContentPlaceHolder1"
Runat="Server">
<div class="content_inc_small">
<table cellpadding="5" cellspacing="0"
border="0" style="width: 100%" >
<tr>
<td style="width: 100px">Artist:</td>
<td style="width: 100px">Record name:</td>
</tr>
<tr>
<td style="width: 100px">Record company:</td>
<td style="width: 100px">Release year:</td>
</tr>
<tr>
<td style="width: 100px">Record number:</td>
<td style="width: 100px">Barcode:</td>
</tr>
<tr>
<td style="width: 100px"> </td>
<td style="width: 100px"> </td>
</tr>
<asp:Repeater runat="server" ID="rprLetterTContent"
OnItemCommand="rprLetterTContent_ItemCommand">
<ItemTemplate>
<tr>
<td style="background-color:#0f0e0c"><a
href="viewsinglerecord.aspx?ID=<%# Eval
("ID")%>"><%# Eval
("artist")%></a></td>
<td style="background-color:#0f0e0c"><%# Eval
("recordname")%></td>
</tr>
<tr>
<td style="background-color:#0f0e0c"><%# Eval
("recordcompany")%></td>
<td style="background-color:#0f0e0c"><%# Eval
("releasedate")%></td>
</tr>
<tr>
<td style="background-color:#0f0e0c"><%# Eval
("recordnumber")%></td>
<td style="background-color:#0f0e0c"><%# Eval
("barcode")%></td>
</tr>
<tr>
<td
style="background-color:#0f0e0c"> </td>
<td
style="background-color:#0f0e0c"> </td>
</tr>
</ItemTemplate>
<AlternatingItemTemplate>
<tr>
<td style="width: 100px"><a
href="viewsinglerecord.aspx?ID=<%# Eval
("ID")%>"><%# Eval
("artist")%></a></td>
<td style="width: 100px"><%# Eval
("recordname")%></td>
</tr>
<tr>
<td style="width: 100px"><%# Eval
("recordcompany")%></td>
<td style="width: 100px"><%# Eval
("releasedate")%></td>
</tr>
<tr>
<td style="width: 100px"><%# Eval
("recordnumber")%></td>
<td style="width: 100px"><%# Eval
("barcode")%></td>
</tr>
<tr>
<td style="width: 100px"> </td>
<td style="width: 100px"> </td>
</tr>
</AlternatingItemTemplate>
</asp:Repeater>
</table>
</div>
</asp:Content>
My t.aspx.cs file looks like this:
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;
public partial class _LetterT : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
rprLetterTContent.DataSource = csLetterT.GetAll();
rprLetterTContent.DataBind();
}
protected void rprLetterTContent_ItemCommand(object source,
RepeaterCommandEventArgs e)
{
}
}
my csLetterT.cs looks like this:
using System.Data.Odbc;
using System;
using System.Data;
using System.Configuration;
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;
/// <summary>
/// Summary description for bllinformation
/// </summary>
public class csLetterT
{
public static DataTable GetAll()
{
// Hämtar ut samtliga medlemmar från databasen.
return DataAccessLayer.GetData(new OdbcCommand("SELECT * FROM
bocken_vinyl WHERE artist LIKE 't%' Order By artist, recordname"));
}
}
Ok... So far soo good.
Note the following code in my t.aspx file:
<td style="width: 100px"><a
href="viewsinglerecord.aspx?ID=<%# Eval
("ID")%>"><%# Eval
("artist")%></a></td>
What i'm thinking of is doing something like the old classic asp.
So her's my viewsinglerecords.aspx file:
<%@ Page Language="C#"
MasterPageFile="~/MasterPage.master" AutoEventWireup="true"
CodeFile="viewsinglerecord.aspx.cs"
Inherits="_viewsinglerecord" Title="Bocken Records :: Collecting
records :: Records" %>
<asp:Content ID="Content1"
ContentPlaceHolderID="ContentPlaceHolder1"
Runat="Server">
<div class="content_inc_header">
VIEW RECORD
</div>
<div class="content_inc_small">
<table border="0" cellpadding="5" style="width:
100%">
<tr>
<td style="width: 100px">Artist
</td>
<td style="width: 100px">Record name:
</td>
<td style="width: 100px">Record company
</td>
<td style="width: 100px">Record number:
</td>
<td style="width: 100px">Barcode:
</td>
</tr>
<asp:Repeater runat="server"
ID="rprViewSingleRecordContent"
OnItemCommand="rprViewSingleRecordContent_ItemCommand">
<ItemTemplate>
<tr>
<td style="width: 100px"><%# Eval
("artist")%>
</td>
<td style="width: 100px"><%# Eval
("recordname")%>
</td>
<td style="width: 100px"><%# Eval
("recordcompany")%>
</td>
<td style="width: 100px"><%# Eval
("varnishedfilmnumber")%>
</td>
<td style="width: 100px"><%# Eval
("Barcode")%>
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
</table>
</div>
</asp:Content>
viewsinglerecords.aspx.cs file:
using System;
using System.Data;
using System.Data.Odbc;
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;
public partial class _viewsinglerecord : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
rprViewSingleRecordContent.DataSource = csViewSingleRecord.GetAll();
rprViewSingleRecordContent.DataBind();
}
protected void rprViewSingleRecordContent_ItemCommand(object source,
RepeaterCommandEventArgs e)
{
}
}
and my csViewSingleRecord.cs file:
using System.Data.Odbc;
using System;
using System.Data;
using System.Configuration;
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;
/// <summary>
/// Summary description for csViewSingleRecord
/// </summary>
public class csViewSingleRecord
{
public static DataTable GetAll()
{
return DataAccessLayer.GetData(new OdbcCommand("SELECT * FROM
bocken_vinyl WHERE ID = @ID"));
}
}
How do i manage to show content only for a specific ID? Help me out as i don't
understand to fix this. Sorry for all the code but i wanted to show them so you
can help me out (hopefully easier).
Thank you very much for the help!
Best regards Johan
|
| Post Reply
|
|
|
|
|
|
|
|
|
|