Datagrid window.open

Discussion in 'ASP .Net Datagrid Control' started by Jack, Mar 16, 2005.

  1. Jack

    Jack Guest

    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
    Jack, Mar 16, 2005
    #1
    1. Advertising

  2. 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


    "Jack" <> wrote in message
    news:...
    > 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
    Ken Cox [Microsoft MVP], Mar 17, 2005
    #2
    1. Advertising

  3. Jack

    Jack Burton Guest

    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.



    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
    Jack Burton, Mar 24, 2005
    #3
  4. Hi Jack,

    Yes, it works for me. Did you try my code?

    "Jack Burton" <> wrote in message
    news:u%...
    > 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?
    Ken Cox [Microsoft MVP], Mar 24, 2005
    #4
  5. Jack

    Jack Burton Guest

    All good - it works! I'm not sure what was going before.

    Cheers,
    Jack



    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
    Jack Burton, Mar 24, 2005
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. ml
    Replies:
    0
    Views:
    1,428
  2. ml
    Replies:
    2
    Views:
    4,831
    John C. Bollinger
    Nov 30, 2004
  3. wax
    Replies:
    9
    Views:
    318
  4. Clare Hsiao
    Replies:
    11
    Views:
    245
    Michael Winter
    Feb 13, 2004
  5. PC HUA
    Replies:
    2
    Views:
    383
    PC HUA
    May 19, 2004
Loading...

Share This Page