Cannot access current datasource row for ds bound to datagrid

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);
}
}
 

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,995
Messages
2,570,236
Members
46,821
Latest member
AleidaSchi

Latest Threads

Top