473,405 Members | 2,272 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Repeater - If..Then

I have a repeater in which I would like to do some
conditional processing.

<asp:HyperLink NavigateUrl='<%# Container.DataItem
("Survey") %>' Runat="server" ID="hypSurvey">Open
Survey</asp:HyperLink></td>

In the example above, If the Container.DataItem("Survey")
is null, I don't want to display the "Open Survey" text.
How can I do this using VB?
Nov 18 '05 #1
2 2044
I would create a function that will create that link for you. This is in C#
but you should be able to convert it for what you need.

//html
<ASP:LABEL id="Label1" runat="server"><%# this.GetNavURL(Container.DataItem,
"ctg_key")%>'</ASP:LABEL>

//code behind
public string GetNavURL(object Row, string Column)
{
//here you can check the value
string myval = GetRowValue(Row, Column);
if (myval == null) return "";

return "<a href='../item.aspx?key=" + myval + "'>" + Click Here + "</a>";
}
public static string GetRowValue(object Row, string Column)
{
string val = "";
if (Row is System.Data.DataRowView) val =
((System.Data.DataRowView)Row)[Column].ToString();
if (Row is System.Data.DataRow) val =
((System.Data.DataRow)Row)[Column].ToString();
if (Row is System.Data.Common.DbDataRecord) val =
((System.Data.Common.DbDataRecord)Row)[Column].ToString();
return val;
}

HTH
"Jason" wrote:
I have a repeater in which I would like to do some
conditional processing.

<asp:HyperLink NavigateUrl='<%# Container.DataItem
("Survey") %>' Runat="server" ID="hypSurvey">Open
Survey</asp:HyperLink></td>

In the example above, If the Container.DataItem("Survey")
is null, I don't want to display the "Open Survey" text.
How can I do this using VB?

Nov 18 '05 #2
Thanks. I tried something similar but kept getting a
error when the data item was null.
-----Original Message-----
I would create a function that will create that link for you. This is in C#but you should be able to convert it for what you need.

//html
<ASP:LABEL id="Label1" runat="server"><%# this.GetNavURL (Container.DataItem,"ctg_key")%>'</ASP:LABEL>

//code behind
public string GetNavURL(object Row, string Column)
{
//here you can check the value
string myval = GetRowValue(Row, Column);
if (myval == null) return "";

return "<a href='../item.aspx?key=" + myval + "'>" + Click Here + "</a>";}
public static string GetRowValue(object Row, string Column){
string val = "";
if (Row is System.Data.DataRowView) val =
((System.Data.DataRowView)Row)[Column].ToString();
if (Row is System.Data.DataRow) val =
((System.Data.DataRow)Row)[Column].ToString();
if (Row is System.Data.Common.DbDataRecord) val =
((System.Data.Common.DbDataRecord)Row)[Column].ToString (); return val;
}

HTH
"Jason" wrote:
I have a repeater in which I would like to do some
conditional processing.

<asp:HyperLink NavigateUrl='<%# Container.DataItem
("Survey") %>' Runat="server" ID="hypSurvey">Open
Survey</asp:HyperLink></td>

In the example above, If the Container.DataItem ("Survey") is null, I don't want to display the "Open Survey" text. How can I do this using VB?

.

Nov 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Jax | last post by:
I have an arraylist of objects. This arraylist is bound to a repeater. That repeater then creates a set of controls like so <asp:repeater id="garmentRepeater" runat="server"...
7
by: Scott Schluer | last post by:
Hi All, I have a functioning datagrid on "Page 1" that displays order information for a single order (this is for an e-commerce site). It's actually a combination of a couple datagrids to...
5
by: Darren Smith | last post by:
Hi There, I have a shopping cart app that displays products along with a textbox (to enter quantity) and an image button to add the item to the shopping cart. Please explain why my below...
3
by: Eskimo | last post by:
how do I add a linkbutton or asp:button to a datarepeater and fire an event? I am using this as my example code: ...
3
by: TJS | last post by:
any suggestions on how to autonumber lines in a repeater ?
2
by: Eniac | last post by:
*argh* ... *pull hairs* I've recently started developing from ASP to ASP.NET The switch was fairly smooth since i had done some VB.net before ... then came...FORMS! :) I find it astounding...
8
by: fernandezr | last post by:
I would like to use a user control as a template inside a repeater. Some of the fields in the control should be hidden depending on whether or not there is data. I'm still a ASP .Net newbie so the...
3
by: Webmills | last post by:
Hi all I have a repeater control containing a web user control within its' item template field. Is it possible to pass through a data field into the web user control, such that this is used...
2
by: mj.redfox.mj | last post by:
Hi, I wonder if someone could possibly help with this? I have the following code, which is a nested repeater in turn nesting a datalist. This all works fine, together with my page-behind vb code...
0
by: Lloyd Sheen | last post by:
I have a repeater in which there can be a table cell that has either one or two lines (sep by /br). If the second line would be the same in all occurences of the repeater then the second line is...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.