datagrid conditional Hyperlink

B

Brent Burkart

How do I set up a column in my datagrid which is blank when conditions are
not met? I have certain records which contain additional information. I
want a hyperlink for those records, but a blank for records without
additional information.

Any help is appreciated,

Thanks,
Brent
 
S

Scott

Create a template column and in the control(s) for the template set the visibility of the anchor;
something like:

<asp:templatecolumn>
<itemtemplate>
<asp:Button runat="server" visible='<%# SomeKindOfExpression %>' />
</itemtemplate>
</asp:templatecolumn>

So, for SomeKindOfExpression -- do something that returns a bool; this could be a method on your
code behind class (make sure it's at least protected); or it could be a binding expression, like:
DataBinder.Eval(Container, "DataItem.Flag").ToString().Equals("Value") --- or whatever else makes
sense.

Scott
 
B

Brent Burkart

Thanks Scott,

But I am recieving this error in the html

The active schema does not support the element 'asp:HyperlinkColumn'

Here is the code

<asp:templatecolumn>
<itemtemplate>
<asp:HyperlinkColumn Text="Click" Target="_blank"
DataNavigateUrlField="Productid"
DataNavigateUrlFormatString="shoppingcartsub.aspx?Productid={0}"
HeaderText="Specs2" Visible='<%# DataBinder.Eval(Container.DataItem, "Show")
%>' ></asp:HyperLinkColumn>
</itemtemplate>
</asp:templatecolumn>

Thanks for your help
 
S

Scott

Change HyperLinkColumn to HyperLink -- HyperLinkColumn is for a column of links in a DataGrid;
what you are doing is creating a "template column" which are you inserting a HyperLink....

Scott
 
B

Brent Burkart

Thanks Scott,

When I change it from HyperLinkColumn to HyperLink, I lose the element of
DataNavigateUrlField and DataNavigateUrlFormatString. I am not sure how to
make the hyperlink work without those elements.

Thanks for your help.
Brent
 
S

Scott

Just format it yourself:

<asp:HyperLink ... NavigateUrl='<%# string.Format("shoppingcartsub.aspx?ProductId={0}",
DataBinder.Eval(Container.DataItem, "ProductId")) %>' ../>

You could do something like

<asp:HyperLink ... NavigateUrl='<%# "shoppingcartsub.aspx?ProductId=" +
DataBinder.Eval(Container.DataItem, "ProductId") %>'... />

Scott
 
B

Brent Burkart

Thanks a lot Scott, Things are a go now. You have been very helpful.

Brent
 

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

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top