conditional hyperlink in datagrid

G

Guest

Hi Folks,

I have a question regarding conditional hyperlink in datagrid of asp.net
,c# application

I want to display Hyperlink if my QID values in (1,4,5,6) other wise i
want to display just Qdescription with out hyperlink.


<asp:hyperlinkcolumn headertext="Question" SortExpression="QDescription"
datatextfield="QDescription"
datanavigateurlformatstring="Answers.aspx?QID={0}"
datanavigateurlfield="QID">
</asp:hyperlinkcolumn>


How can I achieve that kind of functionality?

I looked at the following URL

http://www.dotnet247.com/247reference/msgs/45/226672.aspx


But I didn't get solution for my problem.


Any kind of help is greatly appreciated.


Thanking you
Kumar
 
J

Joe Fallon

Change your HTML to look like this:

<ASP:TEMPLATECOLUMN HeaderText="MyCode" SortExpression="code">
<ITEMTEMPLATE>
<ASP:HYPERLINK id="hylCode" runat="server"></ASP:HYPERLINK>
<asp:label id="lblCode" runat="server">
</ITEMTEMPLATE>
</ASP:TEMPLATECOLUMN>

==========================================================
Then use the ItemDataBound event to write some code like this:

If e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType =
ListItemType.AlternatingItem Then

If QID = 1 ... Then
Dim oHylCode As HyperLink = CType(e.Item.FindControl("hylCode"),
HyperLink)
oHylCode.NavigateUrl = "..."
oHylCode.Text = "..."
Else
Dim oLblCode As Label= CType(e.Item.FindControl("lblCode"), Label)
oLblCode .Text = "..."
End If

End If

==========================================================
 

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