I'm trying to find a solution to a problem I'm having in passing a value to one form, "SongsByBand" to another form in my project "ViewDetails". "SongsByBands" is essentially a list of bands with each song played by that band presented in a bullet list. I want to, in some way, navigate from a single song in the bulleted list to the "ViewDetails" Form; ViewDetails takes the song id to access additional information about that specific song. The songs and the bands are contained in separate tables of a SQL Server database and Entity Framework is used to access the fields from each table.
The pertinent code in the "SongsByBand" Form follows:
<asp:Content ID="Content2" ContentPlaceHolderID="cpMainContent" Runat="Server">
<asp:EntityDataSource ID="EntityDataSource1" runat="server">
</asp:EntityDataSource>
<asp:Repeater ID="Repeater1" runat="server" >
<ItemTemplate>
<h3> <asp:Literal ID="Literal1" runat="server"
Text='<%# Eval("Band1")%>'></asp:Literal></h3>
<h4> <asp:Literal ID="Literal2" runat="server"
Text='<%# Eval("Notes")%>'></asp:Literal></h4>
<asp:BulletedList ID="SongList" runat="server" DisplayMode="LinkButton"
DataSource = '<%# Eval("Songs") %>' DataTextField="Title"
DataValueField="Id">
</asp:BulletedList>
</ItemTemplate>
</asp:Repeater>
</asp:Content>
With the accompanying code behind:
public partial class Songs_SongsByBand : BasePage
{
protected void Page_Load(object sender, EventArgs e)
{
using (TRTDevelopmentSongsAndBandsEntities myEntities =
new TRTDevelopmentSongsAndBandsEntities())
{
var AllSongs = from Band in myEntities.Bands.Include("Songs")
orderby Band.Band1
select new { Band.Band1, Band.Notes, Band.Songs };
Repeater1.DataSource = AllSongs.ToList();
Repeater1.DataBind();
}
}
}
[NB: I left out the "using" statements.]
The pertinent code in the "ViewDetails" Form again follows:
<asp:Content ID="Content2" ContentPlaceHolderID="cpMainContent" Runat="Server">
<h1><asp:Label ID="TitleLabel1" runat="server" ></asp:Label></h1><br />
<asp:Label ID="BandLabel1" runat="server" ></asp:Label><br />
<asp:Label ID="SongWriterLabel1" runat="server" ></asp:Label><br />
<asp:Label CssClass="Comments" ID="CommentsLabel1" runat="server"></asp:Label>
<br />
<asp:HyperLink ID="HyperLink2" runat="server" >For Song Clip, Click Here
</asp:HyperLink>
<br/>
</asp:Content>
With the following code behind:
public partial
class Songs_ViewDetails : BasePage
{
protected void Page_Load(object sender, EventArgs e)
{
int songId = Convert.ToInt32(Request.QueryString.Get("SongId"));
using(TRTDevelopmentSongsAndBandsEntities
myEntities = new TRTDevelopmentSongsAndBandsEntities())
mySong = (from r in myEntities.Songs.Include("Band")
where r.Id == songId
select r).SingleOrDefault();
if(mySong != null)
{
TitleLabel1.Text = "Title: - " + mySong.Title;
BandLabel1.Text = "Band/Singer: - " + mySong.Band.Band1;
SongWriterLabel1.Text = "Song Writer(s): - " + mySong.SongWriter;
CommentsLabel1.Text = "Comments: - " + mySong.Comments;
HyperLink2.NavigateUrl = mySong.ClipLink;
HyperLink2.DataBind();
Title = mySong.Title;
MetaDescription = mySong.Comments;
}
}
}
What I have tried:
I have been working on this for several days and attempted a number of approaches to capture the "SongId" and pass it to the "ViewDetails" Form:
I tried using a hyperlink in the "BulletedList" using NavigateUrl with variations of the following syntax:
NavigateUrl='<%# "ViewDetails?SongId=" + Item.Id.ToString() %>'
But the code doesn't recognize Item or ID or something like Song.Id or any other form I can come up with.
As you may note I have inserted DataValueField="Id" and confirmed that the ID retrieved is the appropriate SongId. It's very frustrating to be able to see the value but can find no method to pass it into the "ViewDetails" Form.
Any guidance or pointers that can be offered would be truly appreciated. T