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

Capture SelectedIndexChanged in RadGrid

2 Answers 320 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Pat
Top achievements
Rank 1
Pat asked on 28 Apr 2011, 02:17 PM

How do I setup RadGrid.SelectedIndexChanged programatically?  I get the following error

"No overload for 'RadGrid1_SelectedIndexChanged' matches delegate 'System.EventHandler' "

I am trying to capture when the user clicks the "Go" button


:
:
:
RadGrid RadGrid1 = new RadGrid();
RadGrid1.DataSourceID = "SqlDataSource1";
RadGrid1.MasterTableView.DataKeyNames = new string[] { "Jobnumber" };
RadGrid1.Skin = "Default";
RadGrid1.Width = Unit.Percentage(100);
RadGrid1.PageSize = 5;
RadGrid1.AllowPaging = true;
RadGrid1.AllowSorting = true;
RadGrid1.AutoGenerateColumns = false;
RadGrid1.MasterTableView.PageSize = 15;
RadGrid1.GridLines = GridLines.Both;
RadGrid1.SelectedIndexChanged +=new EventHandler(RadGrid1_SelectedIndexChanged);  // Not work Generates error
:
:
:
       GridButtonColumn buttonColumn = new GridButtonColumn();
       buttonColumn.HeaderText = "Select File";
       buttonColumn.CommandName = "Select";
       buttonColumn.ButtonType = GridButtonColumnType.PushButton;
       buttonColumn.Text = "Go";
       buttonColumn.ItemStyle.HorizontalAlign = HorizontalAlign.Center;

       RadGrid1.MasterTableView.Columns.Add(buttonColumn);
:
:
:
:



    protected void RadGrid1_SelectedIndexChanged(object source, GridCommandEventArgs e)
    {
        if (e.CommandName == "Select")
        {
 
        }

    }







2 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 29 Apr 2011, 06:29 AM
Hello Pat,

I amo not quite sure about your exact requirement. The RadGrid SelectedIndexChanged event  fired when a different item is selected in a data listing control between posts to the server.
 If you want to check for the commandName the better approach is to attach ItemCommand and there check for the command name.
C#:
protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
   {
     if (e.CommandName == "Select")
       {
         //your code.
       }
   }

Thanks,
Shinu.
0
Pat
Top achievements
Rank 1
answered on 29 Apr 2011, 11:47 AM
Thanks your suggestion worked.  I am still in the learning mode with VS.
Tags
Grid
Asked by
Pat
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Pat
Top achievements
Rank 1
Share this question
or