By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,846 Members | 2,107 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,846 IT Pros & Developers. It's quick & easy.

conditional hyperlink in datagrid

P: n/a
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/247referenc...45/226672.aspx
But I didn't get solution for my problem.
Any kind of help is greatly appreciated.
Thanking you
Kumar


Nov 19 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Look at the ItemDataBound EventHandler , you can add methods that allow you
to work the values depending on whats going to be bound

Good read here:
http://aspnet.4guysfromrolla.com/articles/052103-1.aspx

--
Regards

John Timney
ASP.NET MVP
Microsoft Regional Director

"Kumar" <Ku***@discussions.microsoft.com> wrote in message
news:B6**********************************@microsof t.com...
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/247referenc...45/226672.aspx
But I didn't get solution for my problem.
Any kind of help is greatly appreciated.
Thanking you
Kumar

Nov 19 '05 #2

P: n/a
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

================================================== ========
--
Joe Fallon

"Kumar" <Ku***@discussions.microsoft.com> wrote in message
news:B6**********************************@microsof t.com...
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/247referenc...45/226672.aspx
But I didn't get solution for my problem.
Any kind of help is greatly appreciated.
Thanking you
Kumar

Nov 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.