Solved

Alter control property according to datarow value

Posted on 2004-08-04
6
431 Views
Last Modified: 2012-08-13
Hi all, bear with me as I havent meddled with asp.net for a while.

I have a simple datagrid displaying information. One of the columns is a hyperlink control. The link can sometimes be a movie clip and sometimes a jpeg.

Problem:

When it is a movie clip, its fine, you click the link and your media player opens up no problems.

However, when it is a jpeg and u click link, the jpeg loads in the current page (which i do not want).

Now, if i put target=_blank in the control, then... when u click a movie clip link, a blank page is opened as well as the media player.

What I would like to do is (if possible), alter the controls "target" property depending on the type of link.

In windows forms, I would be using the datarow to iterate thru the rows to modify or read them. I am using ASP.NET.

I'd be grateful if someone could give me a hand with this or would appreciate advise on other methods.

thanks,

KS
0
Comment
Question by:saleek
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 28

Expert Comment

by:mmarinov
ID: 11714514
Hi,
have you tried to use DataGrid's event OnItemDataBound
this event is rised when you bind datagrid and you can itarate through the datagrid's rows before they display to the user
Remember that you have to check the if the e.Item.ItemType is ListItemType.Item or ListItemType.AlternatingItem and you have to find the control
for example:

if ( e.Item.ItemType==ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem )
{
    LinkButton LB = (LinkButton)e.Item.FindControl("your link button id");
    //here check the lb's target
}


i'm not sure that target property is directly accessible like LB.Target so if it is not try to use
LB.Attributes["target"]

HTH
Regards,
B..M
0
 
LVL 11

Author Comment

by:saleek
ID: 11715944
Hi, thanks for your help.

I have this so far:

Sub DataGrid1_ItemDataBound(ByVal sender As Object, ByVal e As DataGridItemEventArgs) Handles DataGrid1.ItemDataBound

        If e.Item.ItemType = ListItemType.Item Or _
     e.Item.ItemType = ListItemType.AlternatingItem Then

            Dim theControl As HyperLink
            theControl = e.Item.FindControl("HLk_ViewMedia")

            If e.Item.Cells(8).Text = "Press" Then
                theControl.Target = "_blank"
            Else
                theControl.Target = "_blank"
            End If

        End If
    End Sub

I can find the control and alter its target property - BUT, e.item.cells(8).text is not pulling any value out.

Any ideas??

thanks,

KS
0
 
LVL 11

Author Comment

by:saleek
ID: 11715999
Re: The "Else statement should have target set to "".

thanks.
0
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 
LVL 28

Accepted Solution

by:
mmarinov earned 50 total points
ID: 11716037
it is because when you use templatecolumn in the datagrid the text of it's cell is emptry string
you have to check not the text of the Cells(8) but you have to find the specific control that you are searching for in the cells(8) and the check it's text property

Regards
B..M
0
 
LVL 11

Author Comment

by:saleek
ID: 11716106
I have no idea what the syntax for that would be, could you show me please?

thanks

KS
0
 
LVL 11

Author Comment

by:saleek
ID: 11716301
Got it!

CType(e.Item.Cells(2).FindControl("lbl_Media"), Label).Text

At first it was still showing blank, but that was because bmy label control did not have the dataitem within the "text=" property, but just sitting between the opening and closing label tag.

thanks for your help.


KS
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

632 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question