GridView

R

rosoft

Hi

I'm using a GridView to list data from a table in my database. On of the
fields is a URL and when I click a row in the GridView I want the page to
automaticly open that link. How do I write code to an event i the GridView
so that when I click a row the page opens up the new link in another window?

Lars
 
A

Angel

You are going to need a little Javascript

<script type ="text/javascript">
var win=null;

function NewWindow(mypage,myname,w,h,scroll,pos){


if(pos=="random"){LeftPosition=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;TopPosition=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;}


if(pos=="center"){LeftPosition=(screen.width)?(screen.width-w)/2:100;TopPosition=(screen.height)?(screen.height-h)/2:100;}

else if((pos!="center" && pos!="random") ||
pos==null){LeftPosition=0;TopPosition=20}


settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no';
win=window.open(mypage,myname,settings);}
// Put this in your onclick event

function PopUpWnd()
{
var pg = document.getElementById("id")

NewWindow("CurrencyPage.aspx","abc", 350, 360, "No", "center")
}

</script>


You wire it something like this

<input id="btnChgCurrency" runat="server" type="button" value="Change
Currency" onclick="PopUpWnd()" name="btnChgCurrency" />
 
R

rosoft

Hi
<input id="btnChgCurrency" runat="server" type="button" value="Change
Currency" onclick="PopUpWnd()" name="btnChgCurrency" />

But I donät want a button I want the table (GridView) to display a html
link. I tried to enter html text into the database table but that only
showed the source code for the html link in the Grid View such as

<p><a href="www.url.com/tracl.mp3">A Track</a></p>

When I work with PHP I read data from a table and then create a table.
Couldn't I some how make a C# class that handled this. Read data from a
database into some sort of view and then read the view and create html code
that I then write to the page. Having to do all this in a Java Script? Then
I'm better of with a PHP page. I was told that C# can fix these things
easaly.

Is there any C# classes I can use to create backend modules for my homepage
on the server. Some class where I send for example <asp:Table ID="Table1"
runat="server">......</asp:Table>. And then pass Table1 as a parameter to an
object where the object fills the Table with data?

I just don't want to show the informatin in the database as it is since I
use it to build links depending on who's logged into the page.

Lars
 
G

gnewsgroup

Hi

I'm using a GridView to list data from a table in my database. On of the
fields is a URL and when I click a row in the GridView I want the page to
automaticly open that link. How do I write code to an event i the GridView
so that when I click a row the page opens up the new link in another window?

Lars

The GridView control has a HyperLink field, which might be what you
are looking for. Just google GridView HyperLink.
 
D

David Wier

As an added note, the HyperlinkField has a Target property (relates to the
HTML hyperlink target attribute), so you can easily get it to open in
another window


David Wier
http://aspnet101.com
http://iWritePro.com - One click PDF, convert .doc/.rtf/.txt to HTML with no
bloated markup


Hi

I'm using a GridView to list data from a table in my database. On of the
fields is a URL and when I click a row in the GridView I want the page to
automaticly open that link. How do I write code to an event i the GridView
so that when I click a row the page opens up the new link in another
window?

Lars

The GridView control has a HyperLink field, which might be what you
are looking for. Just google GridView HyperLink.
 
A

Angel

You can do this

Dim cmd As New CommandField
cmd.EditText = "Select"
cmd.ButtonType = ButtonType.Link
cmd.ShowSelectButton = True
grid.Columns.Add(cmd)

or you can do it declaritive
or you can use the wizard

Lot's of choices

But I never link this command button to pop-up window as David is suggesting
 
A

Angel

David,

I went and did a little checking and could not find the Target property or
its use. Could you point us to an example or a link that talks about this
 
A

Angel

Thanks, you know I seen that page before and never understood it until now
when you brought it up.

That's a simple solution.

Thanks again!
aaa
 
R

rosoft

Coul dyou give me a code example

My GridView is called gvTracks. My DataSourse is called sdsMP3Tracks.

Can you use only these two objects to open the mp3 file?

Lars



"gnewsgroup" <[email protected]> skrev i meddelandet
Hi

I'm using a GridView to list data from a table in my database. On of the
fields is a URL and when I click a row in the GridView I want the page to
automaticly open that link. How do I write code to an event i the GridView
so that when I click a row the page opens up the new link in another
window?

Lars

The GridView control has a HyperLink field, which might be what you
are looking for. Just google GridView HyperLink.
 
R

rosoft

Well that's the static way. I need to do it dynamicly. The view inlcudes
several URLs and I wan tto seleft ont view on the GrodView (GV) and then
goto that url.

Imagine a table with lots of hyper links. You click one of them and the url
in the hyper link opens. That's what I want to do. As an example goto the
page at http://www.rosoft.se/. It includes lots of Hyperlinks that I would
like to store in a database. Fields stored would be ShowText and URL. Using
a GV just shows the data in the table as strings. How do I transform the
text in the GV to hyperliks as in the example on my homepage.

Lars
 
Joined
Dec 4, 2007
Messages
16
Reaction score
0
if you want them to do it on any click on any row

try doing this type of code on the rowdatabound method:

for ( int j = 0; j < e.Item.Cells.Count; j++)
{
e.Item.Cells[j].Attributes["onclick"] = " window.location='URL';";
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,077
Latest member
SangMoor21

Latest Threads

Top