Converting a column in a grid to link

J

John Doe

Hi I want to convert a column to a link. All examples I
have seen works with bound columns. I have the following
grid:
<asp:datagrid runat="server" id="__theDetailsGrid"
cellpadding="2" cellspacing="0"
OnItemDataBound="Details_Item_Bound">
</asp:datagrid>

It is bound during runtime to a DataTable that is bound to
a SqlDataAdapter. The Details_Item_Bound function changes
the background color based on a value. I have been able to
get that to work with the following code:

private void Details_Item_Bound(object sender,
DataGridItemEventArgs e)
{
if((e.Item.ItemType == ListItemType.Item) ||
(e.Item.ItemType == ListItemType.AlternatingItem))
{
if(e.Item.Cells[1].Text == "FAILED")
{
foreach(TableCell c in e.Item.Cells)
{
c.BackColor = System.Drawing.Color.Red;
}
}
}
}
}

Basically what I would like to do is to set the text in
column number 3 to a hypertext link that will point to
another page if the value is "FAILED" in column 1


Hope you guys understand what I would like to acomplish.
 
D

Darrin J Olson

I think I understand what you want.

Can you do this, or something along this idea?:

private void Details_Item_Bound(object sender,
DataGridItemEventArgs e)
{
if((e.Item.ItemType == ListItemType.Item) ||
(e.Item.ItemType == ListItemType.AlternatingItem))
{
if(e.Item.Cells[1].Text == "FAILED")
{

//Add this to make the 4th column (3rd index) a link.
e.Item.Cells[3].Text = "<a href=\"AnotherPage.aspx\">" +
e.Item.Cells[3].Text + said:
foreach(TableCell c in e.Item.Cells)
{
c.BackColor = System.Drawing.Color.Red;
}
}
}
}


John Doe said:
Hi I want to convert a column to a link. All examples I
have seen works with bound columns. I have the following
grid:
<asp:datagrid runat="server" id="__theDetailsGrid"
cellpadding="2" cellspacing="0"
OnItemDataBound="Details_Item_Bound">
</asp:datagrid>

It is bound during runtime to a DataTable that is bound to
a SqlDataAdapter. The Details_Item_Bound function changes
the background color based on a value. I have been able to
get that to work with the following code:

private void Details_Item_Bound(object sender,
DataGridItemEventArgs e)
{
if((e.Item.ItemType == ListItemType.Item) ||
(e.Item.ItemType == ListItemType.AlternatingItem))
{
if(e.Item.Cells[1].Text == "FAILED")
{
foreach(TableCell c in e.Item.Cells)
{
c.BackColor = System.Drawing.Color.Red;
}
}
}
}
}

Basically what I would like to do is to set the text in
column number 3 to a hypertext link that will point to
another page if the value is "FAILED" in column 1


Hope you guys understand what I would like to acomplish.
 
J

John Doe

Hi Darrin
Thanks a million that helped me.
-----Original Message-----
I think I understand what you want.

Can you do this, or something along this idea?:

private void Details_Item_Bound(object sender,
DataGridItemEventArgs e)
{
if((e.Item.ItemType == ListItemType.Item) ||
(e.Item.ItemType == ListItemType.AlternatingItem))
{
if(e.Item.Cells[1].Text == "FAILED")
{

//Add this to make the 4th column (3rd index) a link.
e.Item.Cells[3].Text = "<a href=\"AnotherPage.aspx\">" +
e.Item.Cells[3].Text + said:
foreach(TableCell c in e.Item.Cells)
{
c.BackColor = System.Drawing.Color.Red;
}
}
}
}


Hi I want to convert a column to a link. All examples I
have seen works with bound columns. I have the following
grid:
<asp:datagrid runat="server" id="__theDetailsGrid"
cellpadding="2" cellspacing="0"
OnItemDataBound="Details_Item_Bound">
</asp:datagrid>

It is bound during runtime to a DataTable that is bound to
a SqlDataAdapter. The Details_Item_Bound function changes
the background color based on a value. I have been able to
get that to work with the following code:

private void Details_Item_Bound(object sender,
DataGridItemEventArgs e)
{
if((e.Item.ItemType == ListItemType.Item) ||
(e.Item.ItemType == ListItemType.AlternatingItem))
{
if(e.Item.Cells[1].Text == "FAILED")
{
foreach(TableCell c in e.Item.Cells)
{
c.BackColor = System.Drawing.Color.Red;
}
}
}
}
}

Basically what I would like to do is to set the text in
column number 3 to a hypertext link that will point to
another page if the value is "FAILED" in column 1


Hope you guys understand what I would like to acomplish.


.
 

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,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top