Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Popup from datagrid hyperlink (TemplateColumn)

Status
Not open for further replies.

KDavie

Programmer
Joined
Feb 10, 2004
Messages
441
Location
US
I've read and read and can't seem to an answer specific to my problem.

I have a hyperlink link inside of a datagrid control which resides in a TemplateColumn. I want the window to open as a popup when the hyperlink is clicked. This was straight forward enough when I was using a HyperlinkColumn, however I was unable to pass multiple parameters to the QueryString so I was forced to switch the a TemplateColumn.

Origninally, when I was using the HyperlinkColumn, my code looked like this:
Code:
<asp:HyperLinkColumn Text="Details" DataNavigateUrlField="P_ID" DataNavigateUrlFormatString="javascript:void window.open('P_Details.aspx?P_ID={0}',null,'width=640;height=480;scrollbars=1;resizable=1');"></asp:HyperLinkColum

Now, my code is as such:
Code:
<asp:TemplateColumn>
									<ItemTemplate>
										<asp:HyperLink runat="server" Text="View Details" NavigateUrl='<%#"P_Details.aspx?P_ID="& Container.DataItem("P_ID")&"&LastName="& Container.DataItem("Last_Name")%>' ID="Hyperlink1" />
									</ItemTemplate>
								</asp:TemplateColumn>

Can anyone show me how I can make the latter code open in a popup just as in my previous example?

Any help is appreciated.


Thanks,

Kevin
 
OK,

html

<ItemTemplate>
<asp:HyperLink id=YourID runat="server" Width="48px" NavigateUrl="" Text='<%# DataBinder.Eval(Container, "DataItem.YourFieldName") %>'>
</asp:HyperLink>
</ItemTemplate>

then in th dg itemdatabound you need t odo something like this

Dim DG As DataGrid = CType(sender, DataGrid)
Dim Item As DataGridItem = e.Item
Dim Lnk As HyperLink
Dim Key As Integer

If Item.ItemIndex > -1 Then
Lnk = CType(Item.FindControl("YourLinkName"), HyperLink)
Key = CInt(DG.DataKeys.Item(Item.ItemIndex))
Lnk.NavigateUrl = "YourForm.aspx?Value=" & Key
End If

this should work for you

 
Thanks for your post.

I was just about to post my own solution that I came up with, so if you don't mind perhaps you can tell me if this is good or bad practice.

I ended up creating a function to open up the popup window:

Code:
function openpopup(poplocation, querystring, popheight, popwidth,poptop, popleft){
                var popposition='width='+popwidth+',height='+popheight+',top='+poptop+',left='+popleft;
                if (querystring!=null){
                        poplocation+='?'+querystring;
                }
                var NewWindow = window.open(poplocation,'dialog',popposition);
                if (NewWindow.focus!=null){
                        NewWindow.focus();
                }
        }

Now the code for the hyperlink:

Code:
<asp:TemplateColumn>
									<ItemTemplate>
										<asp:hyperlink runat=server id="lnkpopwindow" Text="View Details" NavigateUrl=<%#"javascript:openpopup('P_Details.aspx','P_ID=" & DataBinder.Eval(Container, "DataItem.P_ID") & "'" & ",400,410,400,410);"%>/>
									</ItemTemplate>
								</asp:TemplateColumn>

It seems to be working well; any feedback?

Thanks again,

-Kevin
 
if it's not broke, don't fix it.....
glad it works for you..

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top