CommandArgument in TemplateColumn

S

Solomon Shaffer

I have a datagrid that I am adding a template column to (containing a couple
of linkbuttons) at runtime and am having some difficulty setting the
commandargument or the linkbuttons. Does anyone know the syntax to databind
the commandargument to the row through code. I am assumning I use the
DataBinder.Eval method but I cannot get it going. Below is the code sample.
Thanks

Solomon

public class KnowlagentDataGridTemplate : ITemplate
{
private ArrayList m_arActionColumnItems;

public DataGridTemplate( ArrayList ActionColumnItems )
{
m_arActionColumnItems = ActionColumnItems;
}

public void InstantiateIn( System.Web.UI.Control oContainer )
{
//Add a new link button for each action in the actions array
for ( int i = 0; i < m_arActionColumnItems.Count; i++ )
{
ActionColumnItem oActionColumnItem =
(ActionColumnItem)m_arActionColumnItems;
LinkButton lnkAction = new LinkButton();
lnkAction.Text = oActionColumnItem.ActionText;
lnkAction.CommandArgument = ******DataBinder.Eval( oContainer.DataItem,
oActionColumnItem.CommandArgument );*****//This not working
//lnkAction.CommandArgument = oActionColumnItem.CommandArgument;
lnkAction.CommandName = oActionColumnItem.ActionText;
lnkAction.Attributes.Add("runat","server");
lnkAction.ID = "lnkAction" + i;
oContainer.Controls.Add( lnkAction );

if ( i < m_arActionColumnItems.Count - 1 )
{
oContainer.Controls.Add( new LiteralControl( "&nbsp;|&nbsp;" ) );
}
}
}
}

public class ActionColumnItem
{
protected string sActionText;
protected string sCommandArgument;

public string ActionText
{
get
{
return sActionText;
}
set
{
sActionText = value;
}
}

public string CommandArgument
{
get
{
return sCommandArgument;
}
set
{
sCommandArgument = value;
}
}

public ActionColumnItem( string ActionText, string CommandArgument )
{
sActionText = ActionText;
sCommandArgument = CommandArgument;
}
}
 

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,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top