I have a class that inherits from GridBoundColumn (TextFilterButtonColumn.cs) in order to add some custom filtering. I then use TextFilterButtonColumn to create columns within a RadGrid. I would like to add a click event to each item in the column. I've done the following within TextFilterButtonColumn.cs:
In the Common.js file I have the following function:
This click event is then accessed inside of the RadGrid ItemCommand event by setting the CommandName property of the GridBoundColumn to "commandName" and checking for it:
I was hoping to access the Id of the row that the radgrid is bound to by calling GetDataKeyValue however this always returns 1. Is there a way to access information regarding the datasource for that row in the ItemCommand event? Or is there another way to accomplish this? Thanks.
public override void Initialize() { base.Initialize(); Owner.Page.ClientScript.RegisterClientScriptResource(this.GetType(), "Common.js"); } public override void PrepareCell(TableCell cell, GridItem item) { base.PrepareCell(cell, item); if (!(item is GridDataItem)) return; var clickScript = string.Format("javascript:tfbc_Click('{0}','{1}');", this.Owner.ClientID, CommandName); var linkButton = new HtmlAnchor() { ID = "lnk", InnerText = cell.Text, HRef = clickScript }; cell.Controls.Clear(); cell.Controls.Add(linkButton); }In the Common.js file I have the following function:
function tfbc_Click(owner, command, argument) { $find(owner).fireCommand(command, argument); }This click event is then accessed inside of the RadGrid ItemCommand event by setting the CommandName property of the GridBoundColumn to "commandName" and checking for it:
if(e.CommandName == "commandName") { var item = (GridDataItem) e.Item; var strKey = item.GetDataKeyValue("Id").ToString(); var control = (Details)Page.LoadControl("~/Controls/Details.ascx"); control.Id = long.Parse(strKey); MPS.AddPopup(control); }I was hoping to access the Id of the row that the radgrid is bound to by calling GetDataKeyValue however this always returns 1. Is there a way to access information regarding the datasource for that row in the ItemCommand event? Or is there another way to accomplish this? Thanks.