ASP.Net - ListVIew - Add a Button Which Opens a Popup window

ASP.Net - ListView - Add a button which opens a popup window

You do this the same way that you do this using a GridView control.

First - add a button on the form. Notice the OnClientClick event

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<ItemTemplate>
<tr><td><asp:ImageButton
ID='btnUpdate'
runat="server"
ImageUrl=".\Graphics\Zoom.gif"
OnClientClick='<%#CreateDatabaseLink(Eval("theKey"))%>'
tooltip="Zoom"
/></td>
<td><%#Eval("Database_Code")%></td>
<td><%#Eval("DatabaseName")%></td>
<td><%#Eval("Description")%></td>
<td></td>
</tr>
</ItemTemplate>

The thing is … we need 3 sets of quotes, but visual studio (and the compiler) can only deal with 2. To get around this we call a procedure - which generates the function.

On the code behind form add the CreateDatabaseLink.. function:

1
2
3
4
5
6
Protected Function CreateDatabaseLink(ByVal Guid As String) As String
If Guid = "" Then
Return ""
End If
Return "openDatabase('" & Guid & "'); return false;"
End Function

When you view the source of the code generated you’ll see
… onclick=”openDatabase(‘c21bef0b-778d-4cf6-aaee-18fc3386fdb4’); return false;” l…

To finish this, you’ll need to add some javascript to the form. (the openDatabase function)

1
2
3
4
5
<script>
function openDatabase(x) {
window.open("frmDB_Edit.aspx?db=" + x + "&mode;=window");
}
</script>