This is a migrated thread and some comments may be shown as answers.

LinkButton in RadGrid GridTableCell with Static ID does not fire ItemCommand Event

3 Answers 152 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Katie Arnott
Top achievements
Rank 1
Katie Arnott asked on 21 Jan 2014, 11:02 PM
I have a LinkButton control that I am adding to a GridTableCell, but when I assign it an ID, the Item Command Event does not fire.

	    ///WORKS
	    LinkButton linkButton = new LinkButton();
            linkButton.Text = name;
            linkButton.CommandArgument = locationString;
            //linkButton.ClientIDMode = System.Web.UI.ClientIDMode.Static;
            //linkButton.ID = string.Concat("LinkButton_", Guid.NewGuid().ToString("N"));
            //linkButton.CommandName = string.Concat("LocationNameLink_", linkButton.ID);            
            linkButton.CommandName = "LocationNameLink";   
               return linkButton; ///DOES NOT WORK
	    LinkButton linkButton = new LinkButton();
            linkButton.Text = name;
            linkButton.CommandArgument = locationString;
            linkButton.ClientIDMode = System.Web.UI.ClientIDMode.Static;
            linkButton.ID = string.Concat("LinkButton_"Guid.NewGuid().ToString("N"));
            linkButton.CommandName = string.Concat("LocationNameLink_", linkButton.ID);
	   return linkButton;

Thoughts?

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 22 Jan 2014, 09:46 AM
Hi Katie Arnott,

You may have to use both ItemCreated and ItemDataBound event when creating a control. Please try the below sample code snippet, that i have used to add LinkButtons to the radgrid rows:

C#:
static string val;
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
{
    foreach (GridColumn col in RadGrid1.MasterTableView.Columns)
    {
        if (e.Item is GridDataItem)
        {
            if (col.DataType == typeof(string))
            {
                GridDataItem item = (GridDataItem)e.Item;
                LinkButton linkButton = new LinkButton();
                linkButton.Text = "Select";
                linkButton.ClientIDMode = System.Web.UI.ClientIDMode.Static;
                linkButton.ID = string.Concat("LinkButton_", Guid.NewGuid().ToString("N"));
                val = string.Concat("LocationNameLink_", linkButton.ID);
                linkButton.CommandName = val;
                item[col.UniqueName].Controls.Add(linkButton);
            }
        }
    }
}
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
    foreach (GridColumn col in RadGrid1.MasterTableView.Columns)
    {
        if (e.Item is GridDataItem)
        {
            if (col.DataType == typeof(string))
            {
                GridDataItem item = (GridDataItem)e.Item;
                LinkButton linkButton = new LinkButton();
                linkButton.Text = "Select";                
                linkButton.CommandName = val;
                item[col.UniqueName].Controls.Add(linkButton);
            }
        }
    }
}

Thanks,
Shinu
0
Katie Arnott
Top achievements
Rank 1
answered on 23 Jan 2014, 07:02 PM
I can't get this to work either, although the grid does reload; just doesn't go into my Item Command Event.

 What LinkButton would cause the ItemCommand Event to trigger? 
0
Shinu
Top achievements
Rank 2
answered on 24 Jan 2014, 04:22 AM
Hi Katie Arnott,

Can you try setting EnableViewState="false" and check if the ItemCommand fires. If this doesn't help, please share your full code snippet:

ASPX:
<telerik:RadGrid EnableViewState="false">

Thanks,
Shinu
Tags
Grid
Asked by
Katie Arnott
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Katie Arnott
Top achievements
Rank 1
Share this question
or