Dropdown event with in gridview not working. RRS feed

  • Question

  • User809322603 posted

    Hi friend i have two dropdown list in gridview i want to bind the second dropdown list when user select something from the first dropdown list

    i tried to bind the second dropdown list on selected indexchenged event of first dropdown list but this is not woking .

    Kinldy see the code below.

    this is aspx page.

    <asp:GridView ID="grdManualTask" runat="server" AutoGenerateColumns="False" 
                                                        BackColor="LightGoldenrodYellow" BorderColor="Tan" BorderWidth="1px" 
                                                        CellPadding="2" EnableModelValidation="True" ForeColor="Black" 
                                                        GridLines="None" onrowdatabound="grdManualTask_RowDataBound" 
                                                        <AlternatingRowStyle BackColor="PaleGoldenrod" />
                                                    <asp:TemplateField HeaderText="Project">
                                                        <asp:DropDownList ID="ddlProject" runat="server" 
                                                     <asp:TemplateField HeaderText="Task">
                                                     <asp:DropDownList ID="ddlTask" runat="server">
                                                     <asp:TemplateField HeaderText="Hours" >
                                                    <asp:TextBox ID="txtHours" runat="server" CssClass="Combotext"></asp:TextBox>                                              
                                                     <asp:TemplateField HeaderText="Description">
                                                    <asp:TextBox ID="txtDescription" runat="server" TextMode="MultiLine" CssClass="Combotext" ></asp:TextBox>                                                                                         
                                                        <FooterStyle BackColor="Tan" />
                                                        <HeaderStyle BackColor="Tan" Font-Bold="True" />
                                                        <PagerStyle BackColor="PaleGoldenrod" ForeColor="DarkSlateBlue" 
                                                            HorizontalAlign="Center" />
                                                        <SelectedRowStyle BackColor="DarkSlateBlue" ForeColor="GhostWhite" />

    this .cs page

            protected void grdManualTask_RowDataBound(object sender, GridViewRowEventArgs e)
                if (e.Row.RowType == DataControlRowType.DataRow)
                    var ddl = (DropDownList)e.Row.FindControl("ddlProject");
                    string qry = "SELECT PR.ProjectName,PR.ClassCode "
                              + " FROM ProjectRequest AS PR"
                              + " INNER JOIN ProjectOwnership AS PO"
                              + " ON PR.ProjectReqID=PO.ProjectReqID"
                              + " WHERE PR.Status='Opened'"
                              + " AND PO.OwnerType='Primary'";
                    ddl.DataSource = objTimeSheet.returnDatatable(qry); 
                    ddl.DataTextField = "ProjectName";
                    ddl.DataValueField = "ClassCode";
                    ddl.Items.Insert(0, new ListItem("--Select--", "0"));
            protected void ddlProject_SelectedIndexChanged(object sender, EventArgs e)
                GridViewRow row = (GridViewRow)((DropDownList)sender).Parent.Parent;
                DropDownList ddlProject = (DropDownList)row.FindControl("ddlProject");
                DropDownList ddlTask = (DropDownList)row.FindControl("ddlTask");
                string qry = "SELECT TaskDescription,TaskCode From task WHERE classCode='" + ddlProject.SelectedValue + "'";
                ddlTask.DataSource = objTimeSheet.returnDatatable(qry);
                ddlTask.DataTextField = "TaskDescription";
                ddlTask.DataValueField = "TaskCode";
                ddlTask.Items.Insert(0, new ListItem("--Select--", "0"));

    Tuesday, September 24, 2013 4:58 AM


  • User289622470 posted


      Since your dropdown list in inside a grid view SelectedIndexChanged will not be fired. All the events inside the grid view will be bublled up to GridView ItemCommand event. So you need to use this event to do any operation.


    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, September 24, 2013 5:23 AM