You will need to access the DataBoundLiteralControl[^] in the same manner you have the LinkButton. The templated column is different from the bound column in that is implements the control collection for displaying its contents. In order to access the value of the templated column, you will need to evaluate the appropiate member of its control collection. =============== Sample DataGrid Code
<asp:DataGrid ID="dgAdmin" Runat="server" DataKeyField="Id" AutoGenerateColumns="False">
<Columns>
<asp:BoundColumn DataField="Id" HeaderText="Id" />
<asp:BoundColumn DataField="Value1" HeaderText="Value1" />
<asp:BoundColumn DataField="Value2" HeaderText="Value2" />
<asp:TemplateColumn HeaderText="Delete">
<ItemTemplate>
<asp:LinkButton ID="lnkDelete" Runat="server">Delete
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
=============== Event Code
private void dgAdmin_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if (e.Item.ItemType != ListItemType.EditItem)
{
//## First, make sure we're NOT dealing with a Header or Footer row
if (e.Item.ItemType != ListItemType.Header)
{
if (e.Item.ItemType != ListItemType.Footer)
{
//## Now, reference the LinkButton control that the Delete ButtonColumn has been rendered to
System.Web.UI.WebControls.LinkButton deleteButton;
deleteButton = (LinkButton)e.Item.FindControl("lnkDelete");
//## ADDITIONAL CODE
System.Web.UI.DataBoundLiteralControl templatedColumn;
templatedColumn = (DataBoundLiteralControl)e.Item.Cells\[2\].Controls\[0\];
//## We can now add the onclick event handler
//deleteButton.Attributes\["onclick"\] = "javascript:return confirm('Template Column: " + e.Item.Cells\[1\].Text + " | DataBound Column: " + e.Item.Cells\[2\].Text +"');";
//## MODIFIED CODE
deleteButton.Attributes\["onclick"\] = "javascript:return confirm('Template Column: " + e.Item.Cells\[1\].Text + " | DataBound Column: " + templatedColumn.Text +"');";
}
}
}
}