我有一个asp网格,数据正确来自数据库并加载到网格中。在该网格中我有一个按钮列。然后单击该按钮我要打开新窗口。我正在使用RowDataBound。我是使用此代码。
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代码:
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')");
}
}
答案 0 :(得分:0)
尝试添加&#39; _blank&#39;参数进入你的javascript代码
lnk.Attributes.Add("onClick", "window.open('Frm_RefundRequestforAdmin.aspx?
DisplayID= " + DisplayID + "', '_blank','Support','width=600',height=500, location=1,
menubar=no')");
希望这有帮助!如果没有,请查看此网站
答案 1 :(得分:0)
试试这个:
lnk.Attributes.Add("onclick", @"window.open('Frm_RefundRequestforAdmin.aspx?
DisplayID=" + DisplayID + @"','Support','width=600,height=500,location=1,
menubar=no')");
问题是您要将所有窗口属性分隔为参数。 为简化起见,您总是可以使其更具可读性:
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);