Converting a column in a grid to link

  • Thread starter Thread starter John Doe
  • Start date Start date
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.
 
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.
 
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.


.
 
Back
Top