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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Datagrid SelectedIndexChanged

Status
Not open for further replies.

BasicBoy

Programmer
Feb 22, 2008
156
ZA
I have a datagrid bound to data - but when I click on it, it does not fire the datagrid.selectedindexchanged event.
What can the problem be ?

Thanks
BB
 
have you wired the handler to the event? this can be done in markup, or code behind.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
No I have not specifically - I thought it is automatically wired up if you double click the control and write the event code.
Can you tell me how to wire up

Thanks
BB
 
either
Code:
<asp:gridview onselectedindexchanged="do_something" >
or
Code:
protected override OnInit(EventArgs e)
{
   base.OnInit(e);
   my_grid_view.SelectedIndexChanged += do_something; 
}

then you will have the handler
Code:
protected void do_something(object sender, GridViewSelectedIndexChangedEventArgs e)
{
   // your code here.
}

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Thanks jmeckley
1. Slower please - I have not done this before. I am working in vb.net and not C# - your code looks like C#.
2. Where do I put protected override - is it in the #Region
3. Where will I see the protected void - do something.
4. Is do something a routine in code behind ?
 
Here is a routine in another web program which works and it triggers the event but I do not know why here and why not in my new program

Public Sub dgCats_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dgCats.SelectedIndexChanged

Dim IDNo As Integer, ThisCatname As String
IDNo = dgCats.SelectedItem.Cells(0).Text
ThisCatname = dgCats.SelectedItem.Cells(1).Text
Response.Redirect("listings.aspx?Type=Cat&ID=" & IDNo)
End Sub
 
Post your HTML source code and any code-behind code that you have.
 
1. C#, there are translators on the web.
2. in the code behind. #regions are for people, not the compiler. I don't use them as it makes it easy to have member explosion within a class.
3. in code behind
4. yes

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top