Link from Repeater component

V

Viktor Popov

Hi,

I'm trying to do the following:
I use a repeater control in ASP.NET/C# because I would like to show the
content of one DataSet which is filled from SELECT QUERY.
In DataSource I have the detailed information for all advertisements which
met the criteria of the QUERY.
With the Repeater I show only one part from this information. In other words
if I have in DataSet 12 columns, I show 6.
What I would like to do is to make the first column ,which the Repeater
shows, a HyperLink to the detailed information of the advertisement.

Repeater shows the following:

TypeEstate Price SquareMeters City
Date RealName
==============================================================
house $333000 500 Sofia
23/08/03 Viktor Popov
apartment $450000 200 Plovdiv
24/07/04 Ilian Peev
...........

What I'm trying to do is to make the TypeEstate link to the detailed
info for the specific advertisement and to show this information in another
WebForm.
How could be accomplished that ?

This is the code which I use now:

C#:
========

private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
SqlConnection conn = new SqlConnection("Data Source=BLEK;Initial
Catalog=Estate; User ID=blek; Password=banderas");
SqlDataAdapter dad = new SqlDataAdapter("SELECT
U.REALNAME,E.ADDATE,ET.TYPEEST,O.PRICE,O.SQMETERS,E.ESTCITY FROM BLEK.USERS
U RIGHT JOIN BLEK.OFFERS O ON U.USERID=O.USERID LEFT JOIN BLEK.ESTATES E ON
O.ESTATEID=E.ESTATEID LEFT JOIN BLEK.Est_TYPE AS ET ON E.ESTTYPEID=ET.TYPEID
LEFT JOIN BLEK.TYPEOFFER AS OT ON E.TYPEOFFERID=OT.OFFERID LEFT JOIN
BLEK.TYPECONSTRUCTION AS TC ON E.TYPECONSTRID=TC.CONSTRID WHERE
E.ESTCITY=@CITY AND OT.TYPEOFFER=@TOFFER", conn);
conn.Open();
dad.SelectCommand.Parameters.Add(new SqlParameter("@CITY",
SqlDbType.VarChar,20));
dad.SelectCommand.Parameters["@CITY"].Value = Session["city"].ToString();
dad.SelectCommand.Parameters.Add(new SqlParameter("@TOFFER",
SqlDbType.VarChar,20));
dad.SelectCommand.Parameters["@TOFFER"].Value = Session["offer"].ToString();
DataSet ds = new DataSet();
dad.Fill(ds, "Users");
conn.Close();
MyRepeater.DataSource = ds.Tables["Users"].DefaultView;
MyRepeater.DataBind();
}

HTML
===========

<asp:Repeater id="MyRepeater" runat="server">
<HeaderTemplate>
<table width="100%" style="font: 8pt verdana">
<tr style="FONT-WEIGHT: bold; COLOR: #ffffff; BACKGROUND-COLOR:
#c00000">
<th>
TypeEstate
</th>
<th>
Price
</th>
<th>
SquareMeters
</th>
<th>
City
</th>
<th>
Date
</th>
<th>
Sender
</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr style="background-color:FFDEAD; COLOR:#c00000">
<td>
<%# DataBinder.Eval(Container.DataItem, "typeest") %>
</td>
<td>
<%# DataBinder.Eval(Container.DataItem, "price", "EU {0}") %>
</td>
<td>
<%# DataBinder.Eval(Container.DataItem, "sqmeters") %>
</td>
<td>
<%# DataBinder.Eval(Container.DataItem, "estcity") %>
</td>
<td>
<%# DataBinder.Eval(Container.DataItem, "addate" ) %>
<td>
<%# DataBinder.Eval(Container.DataItem, "realname" ) %>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
 
B

Bipin Joshi [MVP]

Hi,
If I understand your question correctly this should work for you...

You have used <%# DataBinder.Eval(Container.DataItem, "typeest") %>
Use <asp:HyperLink> control instead such as:
<asp:HyperLink id="lnkGo" runat="server" Text='<%#
DataBinder.Eval(Container.DataItem, "typeest") %>' NavigateUrl="url
here"></asp:HyperLink>

--
Regards,
Bipin Joshi
Consultant | Microsoft MVP | ASPInsider
The .NET Knowledge Base - www.dotnetbips.com
Looking for .NET Training in Mumbai?
Visit www.binaryintellect.com for details.


Viktor Popov said:
Hi,

I'm trying to do the following:
I use a repeater control in ASP.NET/C# because I would like to show the
content of one DataSet which is filled from SELECT QUERY.
In DataSource I have the detailed information for all advertisements which
met the criteria of the QUERY.
With the Repeater I show only one part from this information. In other words
if I have in DataSet 12 columns, I show 6.
What I would like to do is to make the first column ,which the Repeater
shows, a HyperLink to the detailed information of the advertisement.

Repeater shows the following:

TypeEstate Price SquareMeters City
Date RealName
==============================================================
house $333000 500 Sofia
23/08/03 Viktor Popov
apartment $450000 200 Plovdiv
24/07/04 Ilian Peev
..........

What I'm trying to do is to make the TypeEstate link to the detailed
info for the specific advertisement and to show this information in another
WebForm.
How could be accomplished that ?

This is the code which I use now:

C#:
========

private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
SqlConnection conn = new SqlConnection("Data Source=BLEK;Initial
Catalog=Estate; User ID=blek; Password=banderas");
SqlDataAdapter dad = new SqlDataAdapter("SELECT
U.REALNAME,E.ADDATE,ET.TYPEEST,O.PRICE,O.SQMETERS,E.ESTCITY FROM BLEK.USERS
U RIGHT JOIN BLEK.OFFERS O ON U.USERID=O.USERID LEFT JOIN BLEK.ESTATES E ON
O.ESTATEID=E.ESTATEID LEFT JOIN BLEK.Est_TYPE AS ET ON E.ESTTYPEID=ET.TYPEID
LEFT JOIN BLEK.TYPEOFFER AS OT ON E.TYPEOFFERID=OT.OFFERID LEFT JOIN
BLEK.TYPECONSTRUCTION AS TC ON E.TYPECONSTRID=TC.CONSTRID WHERE
E.ESTCITY=@CITY AND OT.TYPEOFFER=@TOFFER", conn);
conn.Open();
dad.SelectCommand.Parameters.Add(new SqlParameter("@CITY",
SqlDbType.VarChar,20));
dad.SelectCommand.Parameters["@CITY"].Value = Session["city"].ToString();
dad.SelectCommand.Parameters.Add(new SqlParameter("@TOFFER",
SqlDbType.VarChar,20));
dad.SelectCommand.Parameters["@TOFFER"].Value = Session["offer"].ToString();
DataSet ds = new DataSet();
dad.Fill(ds, "Users");
conn.Close();
MyRepeater.DataSource = ds.Tables["Users"].DefaultView;
MyRepeater.DataBind();
}

HTML
===========

<asp:Repeater id="MyRepeater" runat="server">
<HeaderTemplate>
<table width="100%" style="font: 8pt verdana">
<tr style="FONT-WEIGHT: bold; COLOR: #ffffff; BACKGROUND-COLOR:
#c00000">
<th>
TypeEstate
</th>
<th>
Price
</th>
<th>
SquareMeters
</th>
<th>
City
</th>
<th>
Date
</th>
<th>
Sender
</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr style="background-color:FFDEAD; COLOR:#c00000">
<td>
<%# DataBinder.Eval(Container.DataItem, "typeest") %>
</td>
<td>
<%# DataBinder.Eval(Container.DataItem, "price", "EU {0}") %>
</td>
<td>
<%# DataBinder.Eval(Container.DataItem, "sqmeters") %>
</td>
<td>
<%# DataBinder.Eval(Container.DataItem, "estcity") %>
</td>
<td>
<%# DataBinder.Eval(Container.DataItem, "addate" ) %>
<td>
<%# DataBinder.Eval(Container.DataItem, "realname" ) %>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top