c# - How to open page in new tab from GridView? -
i want open page in new tab while clicking on gridview link button. want open new page based on alert type. example, given below grid clicked link button of alert1 should open alert1.aspx page, if alert2 alert2.aspx. etc me find proper solution. thank you.
gridview:

<asp:gridview id="gridview1" runat="server" autogeneratecolumns="false" showheader="false"> <columns> <asp:templatefield headertext="alert type" sortexpression="alert_type"> <edititemtemplate> <asp:label id="label1" runat="server" text='<%# eval("alert_type") %>'> </asp:label> </edititemtemplate> <itemtemplate> <asp:label id="label1" runat="server" text='<%# bind("alert_type") %>'> </asp:label> </itemtemplate> </asp:templatefield> <asp:boundfield datafield="created_time" headertext="created time" readonly="true" sortexpression="created_time" /> <asp:templatefield > <itemtemplate> <asp:linkbutton id="lnk" runat="server" text="click" onclick="lnk_click"> </asp:linkbutton> </itemtemplate> </asp:templatefield> </columns> </asp:gridview> c#:
protected void lnk_click(object sender, eventargs e) { page.clientscript.registerstartupscript(this.gettype(), "openwindow", "window.open('alert1.aspx','_newtab');", true); }
here's solution looking for:
protected void lnk_click(object sender, eventargs e) { linkbutton lnk = sender linkbutton; label label1 = lnk.namingcontainer.findcontrol("label1") label; if (label1.text == "alert1") { page.clientscript.registerstartupscript(this.gettype(), "openwindow", "window.open('alert1.aspx','_blank');", true); } else if (label1.text == "alert2") { page.clientscript.registerstartupscript(this.gettype(), "openwindow", "window.open('alert2.aspx','_blank');", true); } } also, give unique names controls inside gridview.
Comments
Post a Comment