Binding dropdownlist to dropdownlist to detailsview ASP.NET C#

匆匆过客 提交于 2019-12-04 07:38:27
Muhammad Akhtar

You have to put your Dependent dropdown datasource in the parent template field. it will be look like...

 <asp:TemplateField HeaderText="Category">
      <InsertItemTemplate>
        <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" DataSourceID="categoryDataSource"
                        DataTextField="name" DataValueField="categoryid">
                    </asp:DropDownList>
                    <asp:SqlDataSource ID="categoryDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:LibrarySystemConnectionString %>"
                        SelectCommand="SELECT categoryid, name FROM dbo.TblCategory"></asp:SqlDataSource>
                    <asp:SqlDataSource ID="bookDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:LibrarySystemConnectionString %>"
                        SelectCommand="SELECT [categoryid], [booktitle], [bookid] FROM [TblBooks] WHERE ([categoryid] = @categoryid)">
                        <SelectParameters>
                            <asp:ControlParameter ControlID="DropDownList1" Name="categoryid" PropertyName="SelectedValue"
                                Type="Int32" />
                        </SelectParameters>
                    </asp:SqlDataSource>
                </InsertItemTemplate>
            </asp:TemplateField>

     <asp:TemplateField HeaderText="Title">
                <InsertItemTemplate>
                    <asp:DropDownList ID="DropDownList2" runat="server" AutoPostBack="True" DataSourceID="bookDataSource"
                        DataTextField="booktitle" DataValueField="bookid">
                    </asp:DropDownList>
                </InsertItemTemplate>
            </asp:TemplateField>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!