ASP.NET - Gridview SelectedIndexChanged Event
Asked By akash Jonathan on 01-May-09 10:48 PM
hai ,
I have placed GridView Ctrl .. But GridView1_SelectedIndexChanged event is not triggering.... Can anybody help me .. Thank s in advance.
In my Gridview Col1 is displays data from database. Col2 is Dropdownlist Col3 and col4 is Checkbox ctrl Col5 is a button for row Description .. when clicked that modal popup will be rised. I placed this Gridview in Accordion .
Santhosh N replied to akash Jonathan on 01-May-09 11:24 PM
check this one to troubleshoot your problem...
http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/Q_24139207.html
try this way
Ravenet Rasaiyah replied to akash Jonathan on 01-May-09 11:35 PM
Hi
you need register event to gridview then make it like this way
void CustomersGridView_SelectedIndexChanged(Object sender, EventArgs e)
{
// Get the currently selected row using the SelectedRow property.
GridViewRow row = CustomersGridView.SelectedRow;
// Display the company name from the selected row.
// In this example, the third column (index 2) contains
// the company name.
Message.Text = "You selected " + row.Cells[2].Text + ".";
}
thank you
sorry my earlier post, that code for gridview look this
Ravenet Rasaiyah replied to akash Jonathan on 01-May-09 11:52 PM
Hi
you need add your event like this way
First add like this way drop down list to grid view.
<asp:TemplateField>
<ItemTemplate>
<asp:DropDownList ID="ddlInGV" runat="server"
DataSourceID="SqlDataSource1" DataTextField="Name" DataValueField="Name"
onselectedindexchanged="ddlInGV_SelectedIndexChanged" AutoPostback = "true">
</asp:DropDownList>
<asp:DropDownList ID="ddlInGV2" runat="server" AutoPostBack="true"> </asp:DropDownList> </ItemTemplate> </asp:TemplateField>
and in row bound evnt
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
// here you can get control
}
}
thank you
Vasanthakumar D replied to akash Jonathan on 02-May-09 03:17 AM
Hi,
give commandName for the Button as 'Select'..
eg:
<asp:TemplateField>
<ItemTemplate>
<asp:Button ID="Button2" runat="server" Text="Button" CommandName="Select" />
</ItemTemplate>
</asp:TemplateField>
when you click the button the selecedIndexChanged event will rise.
reply
Perry replied to Santhosh N on 02-May-09 03:37 AM
Please do not give experts-exchange link because most of users will not have account with them. You can copy-paste the solution with your explanation and give the link to get more points. Just giving links helps sometime.
Regards.
Cool
Santhosh N replied to Perry on 02-May-09 03:42 AM
You need not have any account to see the solution, just scroll down, you will have posts visible (extreme end)....
cheers
I see this in whole page when I opened your link...I dont think I could see the solution
Perry replied to Santhosh N on 02-May-09 03:46 AM
Strange and i am stumped
Santhosh N replied to Perry on 02-May-09 04:00 AM
I could not see the solutions just now when I opened,
But I bet I saw when I posted and as always you can see the solutions from the site
http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/Q_22729197.html?eeSearch=true
Can you check this too and let me know if that is the case, Kindly, go to the end of the page....
same result....It doesn't have free account. I know that.
Perry replied to Santhosh N on 02-May-09 04:22 AM
I identified the problem...
Santhosh N replied to Perry on 02-May-09 04:52 AM
If you can paste the link in google.com and search and open the search result, then you can see the solutions, thats where I am stumped why I cant see when I Copy and paste the link directly...
thats true :-) Looks like some bug or might be some deal between google and expert exchange.. :-)
Perry replied to Santhosh N on 02-May-09 04:57 AM
yeah...
Santhosh N replied to Perry on 02-May-09 05:00 AM
But, otherwise learnt a lesson, so its always better to describe instead of posting directly the link to the users...
thanks Paresh for pointing out :)
re
vikram kharbanda replied to akash Jonathan on 02-May-09 05:06 AM
Hi,
Just go to desging of you page and right click on the gridview and click on the events and then click on the selected index changed event.Its works fine
Thanks
right
Perry replied to Santhosh N on 02-May-09 05:11 AM
That's good observation. I have been telling to people that always describe the things in your words instead of posting only links....but it always good to give link also from where you refer.
Keep it up good things. :-)
Yeah thats correct!!
Santhosh N replied to Perry on 02-May-09 05:13 AM
Austine replied to Ravenet Rasaiyah on 26-Mar-10 02:16 AM
Hi ,Thank you so much for your Article.
I wanted to ask you to please show me how to add a dropdownlist to the gridview header.
When the selected index changed event happens ,The drop downlist will sort the results of the gridview based on the
selected index of the dropdownlist.
I wanted to uset the dropdownlist to search the database colume to display the results in the Gridview.
I will only display two colums of the Database and use the Dropdownlist to sort the colum of the Database.
Thank you and Please help.
Austine