add a hyperlink in each data field

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!!
 
S

SSW

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top