Solved

Alter control property according to datarow value

Posted on 2004-08-04
6
424 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
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

713 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