Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Alter control property according to datarow value

Posted on 2004-08-04
6
Medium Priority
?
433 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:Ramesh Srinivas
  • 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:Ramesh Srinivas
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:Ramesh Srinivas
ID: 11715999
Re: The "Else statement should have target set to "".

thanks.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 28

Accepted Solution

by:
mmarinov earned 200 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:Ramesh Srinivas
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:Ramesh Srinivas
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
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…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

916 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