G
Guest
Hi,
I am trying to create a DataGrid that has a hyperlink in column 1.
Because of design reasons, the grid will auto generate columns and a
repeater will not work.
this output of the grid after databinding will look like this:
ID(hidden)~Name~isLinked(hidden)
In the Name column, I want to add a link below the name
In the ItemCreated event handler, I am creating a LiteralControl with
varying text depending on the value of the isLinked column and adding it to
the e.Item.Cells[1].Controls collection.
My problem is that I cannot access the value of any column, it is always
blank.
Thank you for any thoughts on fixing this problem.
-Keith
=====================================================
Sample eventhandler code:
=====================================================
private void DataGridResults_ItemCreated(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if((e.Item.ItemType==System.Web.UI.WebControls.ListItemType.AlternatingItem)||(e.Item.ItemType==ListItemType.Item))
{
string url="~/Directory/Controls/";
LiteralControl litctrl=new LiteralControl();
if (e.Item.Cells[2]=="1")
litctrl.Text="<br>Already linked";
else
litctrl.Text="<br><a href='" + url + "LinkUserConfirm.ascx&user_id=" +
e.Item.Cells[0].Text + "'>Create Link</a>";
e.Item.Cells[1].Controls.Add(litctrl);
}
}
I am trying to create a DataGrid that has a hyperlink in column 1.
Because of design reasons, the grid will auto generate columns and a
repeater will not work.
this output of the grid after databinding will look like this:
ID(hidden)~Name~isLinked(hidden)
In the Name column, I want to add a link below the name
In the ItemCreated event handler, I am creating a LiteralControl with
varying text depending on the value of the isLinked column and adding it to
the e.Item.Cells[1].Controls collection.
My problem is that I cannot access the value of any column, it is always
blank.
Thank you for any thoughts on fixing this problem.
-Keith
=====================================================
Sample eventhandler code:
=====================================================
private void DataGridResults_ItemCreated(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if((e.Item.ItemType==System.Web.UI.WebControls.ListItemType.AlternatingItem)||(e.Item.ItemType==ListItemType.Item))
{
string url="~/Directory/Controls/";
LiteralControl litctrl=new LiteralControl();
if (e.Item.Cells[2]=="1")
litctrl.Text="<br>Already linked";
else
litctrl.Text="<br><a href='" + url + "LinkUserConfirm.ascx&user_id=" +
e.Item.Cells[0].Text + "'>Create Link</a>";
e.Item.Cells[1].Controls.Add(litctrl);
}
}