add a hyperlink in each data field

  • Thread starter Thread starter Matthew Louden
  • Start date Start date
M

Matthew Louden

The following prints a table of datagrid:

Dim dt As DataTable = ds.Tables(0)
dgEmployeeInfo.DataSource = dt
dgEmployeeInfo.DataBind()

I want to add a hyperlink in each ID field, so that the user can click it
and see the detailed information of each employee.

I have no idea how to print it row by row in a data grid, please help!!
 
Hi!

Trap ItemDataBound Event for datagrid and Set e.Item.Cells[0].Text value as
hyperlink. U code will look like as below

private void dg_ItemDataBound(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
int i = 0;// Column Number where u want to have hyper link
DataRow dr = ((System.Data.DataRowView)e.Item.DataItem).Row;// this is a
current data Row
if (e.Item.ItemType.ToString() !="Header")
if(e.Item.DataItem !=null)
{
e.Item.Cells.Text = @"<a
href=\"EmplyeeChickPage.aspx\">Emplyee ID</a>";
// U can add hyperlink control dynamically to cell over here
e.Item.Cells
//
}
}

Hope this helps.

Thanks,

sswalia
MCAD, MCSD, OCA
 
Back
Top