Repeater - If..Then

J

Jason

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?
 
G

Guest

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
 
J

Jason

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 + said:
}


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 said:
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?
.
 

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

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,070
Latest member
BiogenixGummies

Latest Threads

Top