ASP.NET - gridview selectedIndexChanged not fire

Asked By chandan on 28-Oct-11 02:46 AM
hello friends

i have taken a master page and in master page taken a update panel and a timer control.In update panel i have taken a gridview control .
 

When i am click on the row of gridview  the SelectedIndexChanged event is not fired .
What may be the problem


please help me


Chandan
Jitendra Faye replied to chandan on 28-Oct-11 02:58 AM

Design you page like this-

.cs code-


protected void GridView2_SelectedIndexChanged(object sender, EventArgs e)

{


//your code


}



.aspx code-

<

asp:ScriptManager ID="ScriptManager1" runat="server">


</asp:ScriptManager>


<asp:UpdatePanel ID="UpdatePanel1" runat="server">


<ContentTemplate>


<asp:GridView ID="GridView2" runat="server"

onselectedindexchanged="GridView2_SelectedIndexChanged">


</asp:GridView>


</ContentTemplate>


</asp:UpdatePanel>


Try this and let me know.

Anoop S replied to chandan on 28-Oct-11 03:08 AM
You need to to wire the gridview control to the SelectedIndexChanged event.SelectedIndexChanged fires only when a row's Select button is clicked, not when any other control on the row is.

<asp:gridview id="CustomersGridView" 
       datasourceid="CustomersSource" 
       autogeneratecolumns="False"
       autogenerateselectbutton="True"
       allowpaging="True" 
       selectedindex="1"
       onselectedindexchanged="CustomersGridView_SelectedIndexChanged"
       onselectedindexchanging="CustomersGridView_SelectedIndexChanging"   
       runat="server" DataKeyNames="CustomerID">

refer this for details
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.selectedindexchanged.aspx#Y684
dipa ahuja replied to chandan on 28-Oct-11 03:13 AM
Make sure you have implemented the SelecteIndexChange Property of gridview:

<asp:GridView ID="GridView1"
runat="server"
onselectedindexchanged="GridView1_SelectedIndexChanged">
protected
 void GridView1_SelectedIndexChanged(object sender, EventArgs e) {    //code }

Or try by adding trigger inside update panel


<cc1:UpdatePanel ID="UpdatePanel1" runat="server">
  <ContentTemplate>
    <%--gridview here--%>
  </ContentTemplate>
  <Triggers>
      <asp:AsyncPostBackTrigger ControlID="GridView1" EventName="SelecteIndexChanged" />
  </Triggers>
</cc1:UpdatePanel>