通过单击行打开“ Window1.aspx”,通过超链接打开“ Window2.aspx”
---
.aspx
<asp:GridView ID="GridView1" runat="server" AllowPaging="true" AllowCustomPaging="true" AllowSorting="true" AutoGenerateColumns="false" PageSize="10"
OnSelectedIndexChanged="GridView1_SelectedIndexChanged"
OnRowDataBound="GridView1_RowDataBound"
OnRowCommand="GridView1_RowCommand">
<Columns>
<asp:TemplateField HeaderText="Caller" SortExpression="T_CALL.CALLER" ItemStyle-Width="150px" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:HyperLink ID="Caller" runat="server" Target="_blank"
datanavigateurlfields="ID"
NavigateUrl='<%# "AllCalls2.aspx?Caller=" + Eval("T_CALL.CALLER") + "&recordID=" + Eval("T_CALL.RECORD_ID")%>'
ValidateRequestMode="Enabled" Enabled="true"
Text='<%# Eval("T_CALL.CALLER") %>'></asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="T_EVENT_TYPE.EVENT_NAME" HeaderText="Event" SortExpression="T_EVENT_TYPE.EVENT_NAME" ItemStyle-Width="150px" ItemStyle-HorizontalAlign="Left" />
<asp:BoundField DataField="T_CALL.RECIEVER" HeaderText="Receiver" SortExpression="T_CALL.RECIEVER" ItemStyle-Width="150px" ItemStyle-HorizontalAlign="Center" ShowHeader="True" />
<asp:BoundField DataField="RECORD_DATE" HeaderText="Date" SortExpression="RECORD_DATE" ItemStyle-Width="150px" ItemStyle-HorizontalAlign="Center" />
<asp:TemplateField HeaderText="Call ID" Visible="false" ItemStyle-Width="150px" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:Label ID="CallID" runat="server"
Text='<%# Eval("Call_ID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
---
.aspx.cs
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes["onmouseover"] = "this.style.cursor='pointer'; this.style.fontWeight='bold'; ";
e.Row.Attributes["onmouseout"] = "this.style.textDecoration='none',this.style.fontWeight=''; ";
e.Row.Attributes["onclick"] = this.Page.ClientScript.GetPostBackClientHyperlink(this.GridView1, "Select$" + e.Row.RowIndex);
}
//e.Row.Attributes["onclick"] = string.Format("window.open('CurrentCall2.aspx?Caller={0}&CallID={1}','window', resizable='yes');", ((HyperLink)e.Row.FindControl("Caller")).Text, ((Label)e.Row.FindControl("CallID")).Text);
}
---
aspx.cs
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
GetData();
foreach (GridViewRow row in GridView1.Rows)
{
if (row.RowIndex == GridView1.SelectedIndex)
{
row.BackColor = ColorTranslator.FromHtml("#A1DCF2");
row.ToolTip = string.Empty;
row.Style.Add("cursor", "pointer");
row.Attributes["onclick"] = string.Format("window.open('CurrentCall2.aspx?Caller={0}&CallID={1}','window', resizable='yes');", ((HyperLink)row.FindControl("Caller")).Text, ((Label)row.FindControl("CallID")).Text);
}
else
{
row.BackColor = ColorTranslator.FromHtml("#FFFFFF");
row.ToolTip = "Click to select this row";
}
}
}
情况1:需要选择gridview中的任何行。如果按选中的行单击,则打开窗口“ window1.aspx”;如果按超链接单击,则打开“ window2.aspx”。现在,通过单击超链接打开两个窗口“ window1.aspx”和“ window2.aspx”。通过单击“打开window1.aspx”或打开“ window2.aspx”,需要执行一项操作。现在我通过超链接单击两个窗口。
情况2:未在gridview中选择行。单击按行,然后打开窗口“ window1.aspx”,如果单击超链接,则打开“ window2.aspx”。