Click here to Skip to main content
16,017,137 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear All,
I am using Asp.Net VS2010 and C#. I am use Dropdownlist with in Gridview. Dropdownlist onselectedindexchanged not firing i am using following code.

//HTML

ASP.NET
<asp:TemplateField HeaderText = "Action">
           <ItemTemplate>

               <asp:DropDownList ID="ddlCountries" runat="server" CssClass="ddl" Width="110px"
               onselectedindexchanged="ddlCountries_SelectedIndexChanged"  AutoPostBack="true" Enabled="true" >
                   <asp:ListItem Text="---Select---" Value="---Select---"></asp:ListItem>
                   <asp:ListItem Text="Pending" Value="Pending"></asp:ListItem>
                   <asp:ListItem Text="Approve" Value="Approve"></asp:ListItem>
                   <asp:ListItem Text="Cancel" Value="Cancel"></asp:ListItem>
               </asp:DropDownList>
           </ItemTemplate>

     

       </asp:TemplateField>


//Code behind

C#
protected void ddlCountries_SelectedIndexChanged(object sender, EventArgs e)
   {
       string empid = &amp;quot;&amp;quot;;
       string sno = &amp;quot;&amp;quot;;


       DropDownList ddl = (DropDownList)sender;
       GridViewRow row = (GridViewRow)ddl.Parent.Parent;
       int idx = row.RowIndex;

       DropDownList ddlStatus = (DropDownList)row.FindControl(&amp;quot;ddlStatus&amp;quot;);
       Label lblEmpCode = (Label)row.FindControl(&amp;quot;lblSno2&amp;quot;);
       Label lblsno = (Label)row.FindControl(&amp;quot;lblSno&amp;quot;);

       empid = lblEmpCode.Text;

       sno = lblsno.Text;

       string status = &amp;quot;&amp;quot;;

       string ApproveId = empCode;

       if (ddlStatus.Text == &amp;quot;---Select---&amp;quot;)
       {
           return;
       }

       if (ddlStatus.Text == &amp;quot;Approve&amp;quot;)
       {
           status = &amp;quot;Approved&amp;quot;;
       }

       if (ddlStatus.Text == &amp;quot;Pending&amp;quot;)
       {
           status = &amp;quot;Pending&amp;quot;;
       }

       else
       {
           status = &amp;quot;Cancel&amp;quot;;
       }

   }



Any one please help me.

Sorry for my English.

Thanks for Advance!..
Posted
Comments
Did you put a debugger and test?
Member 11889799 9-Dec-15 7:23am    
hi,
i put debugger and test it but it's not firing.
See my answer.
Richard Deeming 9-Dec-15 10:30am    
How are you binding the GridView? It sounds like you're doing it from the Page_Load event, and have forgotten to put the data-binding code inside an if (!IsPostBack) { ... } block.
Saad Saadi 10-Dec-15 2:21am    
It's working at my end, I have run the same code.
Please rebuilt the project or restart Visual Studio.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900