Datagrid window.open

J

Jack

Hi,

I am having trouble opening a new browser window without toolbars etc
from a bound link in a datagrid. Basically my query string is an ID
from the database which is connected to the URL.

So far I have something like this:

<a runat="server" onClick="window.open('<%# "../main/index.aspx?C=" +
DataBinder.Eval Container.DataItem, "MyId")%',
'width=400,height=200,toolbar=no,
menubar=no,scrollbars=yes)' ID="A2">


The message I'm receiving is : The server tag is not well formed

If you could help me out I would be most grateful!

Jack
 
K

Ken Cox [Microsoft MVP]

Hi Jack,

I'd use a little helper function to make the formatting easier. Here's some
code that shows the idea. Let us know if it helps?

Ken
Microsoft MVP [ASP.NET]
Toronto

<asp:datagrid id="DataGrid1" runat="server"
autogeneratecolumns="False" showheader="False">
<columns>
<asp:templatecolumn>
<itemtemplate>
<asp:HyperLink ID="hlnk"
onclick='<%#MakeHlnk(DataBinder.Eval(Container, "DataItem.myID")) %>'
runat="server" Text='<%#DataBinder.Eval(Container, "DataItem.myID") %>'
NavigateUrl='<%#DataBinder.Eval(Container, "DataItem.myID") %>' >
</asp:hyperlink>
</itemtemplate>
</asp:templatecolumn>
</columns>
</asp:datagrid>


Private Sub Page_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
DataGrid1.DataSource = CreateDataSource()
DataGrid1.DataBind()
End If
End Sub

Public Function MakeHlnk(ByVal strID As String) As String
Dim strJS As String
strJS = "javascript:window.open('index.aspx?C="
strJS = strJS & strID & "','_blank',"
strJS = strJS & "'width=400,height=200,toolbar=no,"
strJS = strJS & "menubar=no,scrollbars=yes');return(false)"
Return strJS
End Function

Function CreateDataSource() As DataTable
Dim dt As New DataTable
Dim dr As DataRow
dt.Columns.Add(New DataColumn _
("MyID", GetType(Int32)))
dt.Columns.Add(New DataColumn _
("StringValue", GetType(String)))
dt.Columns.Add(New DataColumn _
("CurrencyValue", GetType(Double)))
dt.Columns.Add(New DataColumn _
("Boolean", GetType(Boolean)))
Dim i As Integer
For i = 0 To 4
dr = dt.NewRow()
dr(0) = i
dr(1) = "Item " + i.ToString()
dr(2) = 1.23 * (i + 1)
dr(3) = (i = 4)
dt.Rows.Add(dr)
Next i
Return dt
End Function 'CreateDataSource
 
J

Jack Burton

Hi thanks for replying.

Should I be using a hyperlink or an anchor? hyperlink doesn't have the
onclick event? did this work for you?

Jack

p.s. sorry for the delay in replying but I've been away.
 

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

Similar Threads

window.open 13
window.open 2
window.open problem 5
window.open question 1
window.open security... 0
Window.Open Function 2
RegisterStartupScript & Window.Open 4
Hyperlink on a datagrid 1

Members online

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,007
Latest member
obedient dusk

Latest Threads

Top