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

Help needed in Inheriting GridBoundColumn

1 Answer 38 Views
Grid
This is a migrated thread and some comments may be shown as answers.
sameer azazi
Top achievements
Rank 1
sameer azazi asked on 29 May 2010, 07:21 AM

I am trying to inherit GridBoundColumn.

where i override preparecell method.

I am putting an ImageButton  in GridDataItem.

now i need to fire owner grid ItemCommand event on this ImageButton's  Click event.

How can i do that?

check out this code.

[ToolboxData("<{0}:ActiveDeactiveColumn runat=server></{0}:ActiveDeactiveColumn>")]
    public class ActiveDeactiveColumn : GridBoundColumn
    {
        public override void PrepareCell(TableCell cell, GridItem item)
        {
          
            if (item is GridHeaderItem)
            {
                Literal lt = new Literal();

                lt.Text = this.HeaderText;

                cell.Controls.Add(lt);
            }

            if (item is GridDataItem)
            {

                ImageButton imgBtn = new ImageButton();

                bool value = (Boolean)DataBinder.Eval(item.DataItem, this.DataField);

                String url = value ? "OSS.Resources.tick.gif" : "OSS.Resources.cross.gif";

                imgBtn.ImageUrl = this.Owner.OwnerGrid.Page.ClientScript.GetWebResourceUrl(this.GetType(), url);

                imgBtn.OnClientClick = "return confirm('Are you sure want to " + (value ? "deactivate" : "activate") + " this record?')";

                imgBtn.CommandName = value ? "deactivate" : "activate";

                //What should be written Here?
                //imgBtn.Click += ""???
               // how can i bind this.owner.ownerGrid.ItemCommand (RadGrid.ItemCommand) event to this ImageButton event?
               
                cell.Controls.Add(imgBtn);
 
            }   

        }
    }




1 Answer, 1 is accepted

Sort by
0
Mira
Telerik team
answered on 03 Jun 2010, 08:18 AM
Hello Sameer,

To achieve the desired functionality, I suggest that you use the FireCommandEvent(eventName, eventArgs) method of the corresponding GridDataItem in the Click event handler of the image button.
Your code could look like:
  void ImageButton_Click(object sender, ImageClickEventArgs e)
 {
      GridDataItem item = (sender
as GridDataItem).NamingContainer as GridDataItem;
      item.FireCommandEvent("CommandName", GridCommandEventArgs);
 }

For additional information, please take a look at the How to fire command events from code help topic.

Greetings,
Mira
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
Grid
Asked by
sameer azazi
Top achievements
Rank 1
Answers by
Mira
Telerik team
Share this question
or