Solved

Alter control property according to datarow value

Posted on 2004-08-04
6
415 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
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 
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

ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

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

Suggested Solutions

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
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.

770 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