Solved

Alter control property according to datarow value

Posted on 2004-08-04
6
411 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
Comment Utility
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
Comment Utility
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
Comment Utility
Re: The "Else statement should have target set to "".

thanks.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 28

Accepted Solution

by:
mmarinov earned 50 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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 Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now