Welcome reader. In this post, we want to discuss how to load DropDownList after selectedindexchanged another DropDownList in gridview. Before we get started, if you want to need the activation key or a Serial number of Visual Studio 2015, please go through the following article: Activation key of Visual Studio 2015.
We use three dropdownlist in the gridview, after change first dropdownlist second dropdownlist data will load. and similarly, when we change the second DropDownList, the third dropdownlist will be loaded. Let’s do it. First, we share asp.net code as following:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
<asp:GridView ID="grdParts" runat="server" AutoGenerateColumns="false" GridLines="Both" HeaderStyle-BackColor="#009ACD" ForeColor="White" Width="100%" ItemStyle-Wrap="true"> <RowStyle CssClass="TableText" Font-Size="8pt" /> <HeaderStyle BorderColor="Black" ForeColor="White" BackColor="#6699CC" /> <AlternatingRowStyle CssClass="AlternatColor" /> <Columns> <asp:TemplateField HeaderText="SL. No"> <HeaderStyle HorizontalAlign="Left" /> <ItemTemplate><%#Container.DataItemIndex+1 %></ItemTemplate> </TemplateField> <asp:TemplateField HeaderText="Parts No"> <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="90px" /> </TemplateField> <asp:TemplateField HeaderText="Rack No"> <ItemStyle HorizontalAlign="Left" VerticalAlign="Top" Width="55px"></ItemStyle> <asp:DropDownList ID="gddlRackNo" runat="server" Width="50px" AutoPostBack="true" CssClass="DropDownList" OnSelectedIndexChanged="gddlRackNo_SelectedIndexChanged"></DropDownList> </asp:TemplateField> <asp:TemplateField HeaderText="Raw No"> <ItemStyle HorizontalAlign="Left" VerticalAlign="Top" Width="55px"></ItemStyle> <asp:DropDownList ID="gddlRawNo" runat="server" Width="50px" AutoPostBack="true" CssClass="DropDownList" OnSelectedIndexChanged="gddlRawNo_SelectedIndexChanged"></DropDownList> </asp:TemplateField> <asp:TemplateField HeaderText="BIN No"> <ItemStyle HorizontalAlign="Left" VerticalAlign="Top" Width="55px"></ItemStyle> <asp:DropDownList ID="gddlBinNo" runat="server" Width="50px" CssClass="DropDownList"></DropDownList> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView> |
After complete asp.net code, we need to write the following c# code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
protected void gddlRackNo_SelectedIndexChanged(object sender, EventArgs e) { DropDownList ddlCDropDownList = (DropDownList)sender; GridViewRow grdrDropDownRow = ((GridViewRow)ddlCDropDownList.Parent.Parent); DropDownList ddlRackNo = (DropDownList)grdrDropDownRow.FindControl("gddlRackNo"); DropDownList ddlRawNo = (DropDownList)grdrDropDownRow.FindControl("gddlRawNo"); DataReader dr = new DataReader(); DataTable dt = dr.GetDataTableByCommand("SELECT RawNo FROM tblCustCareBINMst WHERE RackNo='" + ddlRackNo.SelectedValue.Trim() + "' AND ShowroomID='" + ddlStore.SelectedValue.Trim() + "' ORDER BY RawNo"); if (dt.Rows.Count > 0) { FillList fl = new FillList(); fl.PopulateDDL(dt, ddlRawNo, "RawNo", "RawNo", true, "---", "-1"); } } protected void gddlRawNo_SelectedIndexChanged(object sender, EventArgs e) { DropDownList ddlCDropDownList = (DropDownList)sender; GridViewRow grdrDropDownRow = ((GridViewRow)ddlCDropDownList.Parent.Parent); DropDownList ddlRackNo = (DropDownList)grdrDropDownRow.FindControl("gddlRackNo"); DropDownList ddlRawNo = (DropDownList)grdrDropDownRow.FindControl("gddlRawNo"); DropDownList ddlBinNo = (DropDownList)grdrDropDownRow.FindControl("gddlBinNo"); DataReader dr = new DataReader(); DataTable dt = dr.GetDataTableByCommand("SELECT BinNo FROM tblCustCareBINMst WHERE RackNo='" +Â Â Â Â ddlRackNo.SelectedValue.Trim() + "' and RawNo='" + ddlRawNo.SelectedValue.Trim() + "' AND ShowroomID='" + ddlStore.SelectedValue.Trim() + "' ORDER BY BinNo"); if (dt.Rows.Count > 0) { FillList fl = new FillList(); fl.PopulateDDL(dt, ddlBinNo, "BinNo", "BinNo", true, "---", "-1"); } } |
Leave a Comment