Open a popup / new window from a gridview - VS2010, c#
Can anyone give me any hint on how I can op开发者_StackOverflowen a new window by selecting a record from a gridview? Im using response.redirect, and passing a value at present which opens the page fine but Id rather have a popup for this
thanks
You need to bind click event with the row of the grid view control
following code is just demo for you
following javascript open up the pop up window where you need to pass the url you want
<script>
function popWin(url){
window.open(url, '', '');");
}
</script>
follwing is samle code that attch the script with the gridview row to open up popup
code behind
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if(e.Row.RowType == DataControlRowType.DataRow )
{
string url = "www.google.com";
e.Row.Attributes.Add("onclick","popWin('" + url + "')");
}
}
I had the same issue with response.redirect so went with a asp:HyperLink button instead. I loaded the URL by Binding it through the SQL Database. Here is the code:
<asp:TemplateField HeaderText="Google Map">
<ItemTemplate>
<asp:HyperLink runat="server" ID="hlGMap" Target="_blank" Text="Map" ImageUrl="~/gfx/google.png" NavigateUrl='<%# Bind("GoogleMapsURL") %>' />
</ItemTemplate>
</asp:TemplateField>
Hope it helps.
精彩评论