Click here to Skip to main content
14,879,028 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

Gridview SelectedIndexChanging event  not running with dropdownliist control.


It was showing always 0 index value of dropdownlist.
When i clicked on
Gridview SelectedIndexChanging event



Please help me.

Ankit Agarwal

What I have tried:

<asp:TemplateField HeaderText="Client Response">
                            <ItemTemplate>
                                <asp:Label ID="lblClientResponse" runat="server" Text='<%# Eval("ClientResponse") %>' />
                                <%--   <%#Eval("ClientResponse")%>--%>
                            </ItemTemplate>
                            <EditItemTemplate>
                                <asp:Label ID="lblClientResponse" runat="server" Text='<%# Eval("ClientResponse") %>'
                                    Visible="false" />
                                <asp:DropDownList ID="ddlClientResponse" runat="server" AutoPostBack="True">
                                    <asp:ListItem Value="0">-Select Response-</asp:ListItem>
                                    <asp:ListItem Value="1">Interested</asp:ListItem>
                                    <asp:ListItem Value="2">Not Interested</asp:ListItem>
                                    <asp:ListItem Value="3">Hold</asp:ListItem>
                                    <asp:ListItem Value="4">Call Not Received</asp:ListItem>
                                    <asp:ListItem Value="5">Not Reachable</asp:ListItem>
                                    <asp:ListItem Value="6">Wrong Number</asp:ListItem>
                                    <asp:ListItem Value="7">Switched Off</asp:ListItem>
                                </asp:DropDownList>
                            </EditItemTemplate>
                        </asp:TemplateField>



this code on RowDataBound.
if (e.Row.RowType == DataControlRowType.DataRow)
        {
if (e.Row.RowState == DataControlRowState.Edit || (e.Row.RowState == (DataControlRowState.Edit | DataControlRowState.Alternate)))
        {
            string ClientResponse = (e.Row.FindControl("lblClientResponse") as Label).Text;
            DropDownList ddl = (DropDownList)e.Row.FindControl("ddlClientResponse");
            ddl.Items.FindByText(ClientResponse).Selected = true;
}



ImageButton img = (ImageButton)e.Row.FindControl("img_user");

            if (Status == true)
            {
                img.ImageUrl = "~/images/active.png";
            }
            else
            {
                img.ImageUrl = "~/images/inactive.png";
            }
}


protected void gvDeshboard_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
    {

        bool Status = Convert.ToBoolean((gvDeshboard.Rows[e.NewSelectedIndex].FindControl("lblIsActive") as Label).Text);
        ImageButton img = (ImageButton)gvDeshboard.Rows[e.NewSelectedIndex].FindControl("img_user");
        Label lblIsActive = gvDeshboard.Rows[e.NewSelectedIndex].FindControl("lblIsActive") as Label;
        if (Status == false)
        {
            Status = true;
            ViewState["ClientStatus"] = Status;
            lblIsActive.Text = Convert.ToString(Status);
            
        }
        else
        {
            Status = false;
            ViewState["ClientStatus"] = Status;
            lblIsActive.Text = Convert.ToString(Status);
            //Response.Redirect("SalesExecutive.aspx");
        }

        if (Status == true)
        {
            img.ImageUrl = "~/images/active.png";
        }
        else
        {
            img.ImageUrl = "~/images/inactive.png";
        }

       
        
        string ClientResponse = (gvDeshboard.Rows[e.NewSelectedIndex].FindControl("lblClientResponse") as Label).Text;
        DropDownList ddl = (DropDownList)gvDeshboard.Rows[e.NewSelectedIndex].FindControl("ddlClientResponse");
        ddl.Items.FindByText(ClientResponse).Selected = true;

    }


My image button code:-

<asp:TemplateField HeaderText="Deal Status">
                 <ItemTemplate>
                  <asp:Label ID="lblIsActive" runat="server" Text='<%# Eval("IsActive") %>' />
                  </ItemTemplate>
                  </asp:TemplateField>
                 <asp:TemplateField>
                     <ItemTemplate>
                         <asp:ImageButton ID="img_user" runat="server" CommandName="Select" ImageUrl='<%# Eval("IsActive") %>'
                             Width="50px" Height="30px" />
                     </ItemTemplate>
                 </asp:TemplateField>

                 <asp:TemplateField HeaderText="Edited By">
                     <ItemTemplate>
                         <asp:Label ID="lblEditedBy" runat="server" Text='<%# Eval("EditedBy") %>' />
                         <%--<%#Eval("ClientName")%>--%>
                     </ItemTemplate>
                 </asp:TemplateField>
                 <asp:TemplateField HeaderText="Edit">
                     <ItemTemplate>
                         <asp:Button ID="btnEdit" runat="server" Text="Edit" CommandName="Edit" />
                     </ItemTemplate>
                     <EditItemTemplate>
                         <asp:Button ID="btnUpdate" runat="server" CommandName="Update" Text="Update" />
                         <asp:Button ID="btnCancel" runat="server" CommandName="Cancel" Text="Cancel" />
                     </EditItemTemplate>
                 </asp:TemplateField>
Posted
Updated 27-Oct-17 0:13am
v2
Comments
Karthik_Mahalingam 27-Oct-17 5:53am
   
how are you binding the dropdownlist values
Agarwal1984 27-Oct-17 6:01am
   
<asp:TemplateField HeaderText="Client Response">
<itemtemplate>
<asp:Label ID="lblClientResponse" runat="server" Text='<%# Eval("ClientResponse") %>' />
<%-- <%#Eval("ClientResponse")%>--%>

<edititemtemplate>
<asp:Label ID="lblClientResponse" runat="server" Text='<%# Eval("ClientResponse") %>'
Visible="false" />
<asp:DropDownList ID="ddlClientResponse" runat="server" AutoPostBack="True">
<asp:ListItem Value="0">-Select Response-
<asp:ListItem Value="1">Interested
<asp:ListItem Value="2">Not Interested
<asp:ListItem Value="3">Hold
<asp:ListItem Value="4">Call Not Received
<asp:ListItem Value="5">Not Reachable
<asp:ListItem Value="6">Wrong Number
<asp:ListItem Value="7">Switched Off


Karthik_Mahalingam 27-Oct-17 6:05am
   
why you have used autopostback=true , since there is no event associated to it.
Agarwal1984 27-Oct-17 6:08am
   
actually user can select data from dropdownlist if he will clicked on edit button.
Karthik_Mahalingam 27-Oct-17 6:12am
   
try removing the autopostback=true and check
Agarwal1984 27-Oct-17 6:18am
   
i tried but problem is still.

when i click my image button and then edit button so problem is coming after that.
<asp:ImageButton ID="img_user" runat="server" CommandName="Select" ImageUrl='<%# Eval("IsActive") %>'
Width="50px" Height="30px" />
Let suppose:- my existing dropdown selected "Interested" and i clicked on Status Button and then click on edit button so, my dropdown data has been changed "--Select Response--".

If i did not click Status (ImageButton) button and then click on Edit button so dropdown text maintain like "Interested".
Karthik_Mahalingam 28-Oct-17 5:24am
   
try this
if ((e.Row.RowType == DataControlRowType.DataRow) && (gridview1.EditIndex == e.Row.RowIndex))
{

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

  Print Answers RSS
Top Experts
Last 24hrsThis month



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