简体   繁体   中英

How to open a new window on asp grid column button click?

I have an asp grid,data is properly coming from database and load into grid.In that grid i have a button column.and onclick that button i want to open new window.And i am using RowDataBound in that.I am using this Code.

CODE:

<asp:GridView ID="GridView1" runat="server" CssClass="reference" 
   AllowPaging="True"DataSourceID="SqlDataSource1" AllowSorting="True" 
   EmptyDataText="Oops there is no record found." AutoGenerateColumns="False" 
   DataKeyNames= "DisplayId" OnRowCommand="GridView1_RowCommand" 
   OnRowDataBound="GridView1_RowDataBound" OnSorting="GridView1_Sorting"
   OnPageIndexChanged="GridView1_PageIndexChanged">
   <PagerSettings Mode="NumericFirstLast" />
   <AlternatingRowStyle CssClass="Alt" />
   <Columns>
        <asp:TemplateField>
           <HeaderTemplate>Sno  </HeaderTemplate>
           <ItemTemplate>
                    <%#Container.DataItemIndex + 1%>
           </ItemTemplate>
           <ItemStyle />
               <asp:BoundField DataField="DisplayId" HeaderText="Display Id" 
                        SortExpression="DisplayId"HeaderStyle-HorizontalAlign="Center" 
                        ItemStyle-HorizontalAlign="Center" />
                        <asp:BoundField DataField="Kno" HeaderText="Mobile" 
                         SortExpression="Kno"HeaderStyle-HorizontalAlign="Center"   
                        ItemStyle-HorizontalAlign="Center" />
                       <asp:BoundField DataField="SuccessStatus" HeaderText="Status " 
                   SortExpression="SuccessStatus"
                   HeaderStyle-HorizontalAlign="Center" ItemStyle-
                   HorizontalAlign="Left" />
                   <asp:TemplateField HeaderText="Refund Request">
                       <ItemTemplate>
                          <asp:LinkButton ID="trans" runat="server" CommandName="Trans"     
                          CommandArgument='<%#((GridViewRow)Container).RowIndex 
                           %>'>Refund</asp:LinkButton>
                         </ItemTemplate>
          </asp:TemplateField>
        </Columns>
     </asp:GridView>

     <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
                            ConnectionString="<%$ ConnectionStrings:QOMCS %>">
                            </asp:SqlDataSource>                                
  </ContentTemplate>
  <Triggers>
          <asp:AsyncPostBackTrigger ControlID="GridView1" 
  </Triggers>

.cs Code:

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
     if (e.Row.RowType == DataControlRowType.DataRow)
     {
        string DisplayID = DataBinder.Eval(e.Row.DataItem, "DisplayID").ToString();
        LinkButton lnk = (LinkButton)e.Row.FindControl("trans");
        lnk.Attributes.Add("onClick", "window.open('Frm_RefundRequestforAdmin.aspx? 
        DisplayID= " + DisplayID + "','Support','width=600',height=500, location=1,  
        menubar=no')");
     }
}

Try to add '_blank' parameter into your javascript code like this

 lnk.Attributes.Add("onClick", "window.open('Frm_RefundRequestforAdmin.aspx? 
    DisplayID= " + DisplayID + "', '_blank','Support','width=600',height=500, location=1,  
    menubar=no')");

Hope this help! If not, check this site

http://www.w3schools.com/jsref/met_win_open.asp

try this:

 lnk.Attributes.Add("onclick", @"window.open('Frm_RefundRequestforAdmin.aspx? 
    DisplayID=" + DisplayID + @"','Support','width=600,height=500,location=1,  
    menubar=no')");

Issue is that you are you are separating all windows attributes as parameter. To simplify you can always make it more readable:

 string sWindow = @"'Frm_RefundRequestforAdmin.aspx?DisplayID=" + DisplayID + "'";
 string sWindowName = @"'Support'";
 string sFeatures = @"'width=600,height=500,location=1,menubar=no'";

 lnk.Attributes.Add("onclick", sWindow, sWindowName, sFeatures);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM