Hi georgeacuster...,
Please Refer below sample.
HTML
<asp:GridView ID="gvDetails" runat="server" AutoGenerateColumns="false" OnRowDataBound="OnRowDataBound">
<Columns>
<asp:BoundField DataField="pID" HeaderText="Id" />
<asp:BoundField DataField="Name" HeaderText="Name" />
<asp:TemplateField>
<ItemTemplate>
<asp:HiddenField ID="hfPId" runat="server" Value='<%#Eval("pID") %>' />
<asp:HyperLink ID="hl" runat="server"
Text='<%# Eval("pID") %>'
Target="_blank"
ToolTip='<%# (string.IsNullOrEmpty(Eval("pID").ToString()) ? "No" : "Yes") %>'
Enabled='<%# (string.IsNullOrEmpty(Eval("pID").ToString()) ? false : true) %>'
ImageUrl='<%# (string.IsNullOrEmpty(Eval("pID").ToString()) ? "/aspnet/img/all.gif" : "/aspnet/img/c16.png") %>'
CssClass="_Class_new">
</asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Namesapce
C#
using System.Data;
VB.Net
Imports System.Data
Code
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[] {
new DataColumn("pID"),
new DataColumn("Name")});
dt.Rows.Add("011", "Apple");
dt.Rows.Add("012", "Orange");
dt.Rows.Add("", "Grapes");
gvDetails.DataSource = dt;
gvDetails.DataBind();
}
}
protected void OnRowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
HyperLink h1 = (HyperLink)e.Row.FindControl("hl");
string pId = ((HiddenField)e.Row.FindControl("hfPId")).Value;
if (!string.IsNullOrEmpty(pId))
{
h1.NavigateUrl = string.Format("Default.aspx?spEmpid={0}", pId);
h1.Attributes.Add("onclick", "javascript:w=window.open(this.href, 'pID', 'left=150,top=150,width=1200,height=600,toolbar=0,resizable=0');return false;");
}
}
}
VB.Net
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not Me.IsPostBack Then
Dim dt As DataTable = New DataTable()
dt.Columns.AddRange(New DataColumn() {New DataColumn("pID"), New DataColumn("Name")})
dt.Rows.Add("011", "Apple")
dt.Rows.Add("012", "Orange")
dt.Rows.Add("", "Grapes")
gvDetails.DataSource = dt
gvDetails.DataBind()
End If
End Sub
Protected Sub OnRowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
If e.Row.RowType = DataControlRowType.DataRow Then
Dim h1 As HyperLink = CType(e.Row.FindControl("hl"), HyperLink)
Dim pId As String = (CType(e.Row.FindControl("hfPId"), HiddenField)).Value
If Not String.IsNullOrEmpty(pId) Then
h1.NavigateUrl = String.Format("Default.aspx?spEmpid={0}", pId)
h1.Attributes.Add("onclick", "javascript:w=window.open(this.href, 'pID', 'left=150,top=150,width=1200,height=600,toolbar=0,resizable=0');return false;")
End If
End If
End Sub
Screenshot