Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Datagrid SelectedIndexChanged event will not fire!

Status
Not open for further replies.

mb22

Programmer
Sep 4, 2002
258
US
what could be the problem?
I'm trying to get the row number with
Datagrid1.SelectedIndex bu tthe event is not firing ..

previously i had an Edit button which was firing .. and I thought that was the reason. I removed the Edit button BUT still the SelectedIndex is not firing!
 
Have you looked inside the InitializeComponent sometimes if using VS.NET it does not put it in there for you.
Here is mine for a sort I don't have one handy for SelectedIndexChanged.
code from aspx.cs

private void InitializeComponent()
{
this.dgUserName.SortCommand += new System.Web.UI.WebControls.DataGridSortCommandEventHandler(this.dgUserEmployee_Sort);
this.Load += new System.EventHandler(this.Page_Load);

}

You may want to look in your aspx and make sure
OnSelectedIndexChanged="IndexChange_Command" is there for your control ID.
Marty
 
Make sure that your ViewState is enabled on the page, your grid, and all containers.
 
As the IDE plays with the Initialize Component method it's tricky to manually edit it. You never know when VS will take you changes out. On your aspx page use the OnEventName property to declare which method to call.

For the datagrid this is OnSelectedIndexChanged=method name
Place that on the opening tag of the <asp:DataGrid tag

That'l do donkey, that'l do
[bravo] Mark
If you are unsure of forum etiquette check here faq796-2540
 
Actualy, you don't have to manualy edit the InitializeComponent. In design mode, pull up the properties of the grid, go to the &quot;Events&quot; section of it and just double click on an event name. It'll create a default event handler and an entry inside of the InitializeComponent in the code behind. And like cappmgr said, the event won't fire if it's not registered inside of InitializeComponent.
 
Marty

I have the same problem - when I click on the datagrid I do not get an event that is listed. I do not understand how the tip :

You may want to look in your aspx and make sure
OnSelectedIndexChanged="IndexChange_Command" is there for your control ID.

works

Can someone please help

PK Odendaal
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top