简体   繁体   English

我需要选择下拉列表值时,复选框控件应在asp.net中动态更改

[英]i need that on selection of drop down list value the check box controls should change dynamically in asp.net

Our team is using SQL server as back end. 我们的团队正在使用SQL Server作为后端。 On the web page, we have the values in DropdownList which are reflected dynamically on the STREAM column of a table, which contains data for various Streams( arts, commerce, science, so on).This has been done. 在网页上,我们在DropdownList中具有值,这些值动态反映在表的STREAM列上,该列包含各种Streams(艺术,商业,科学等)的数据。 Now on selection of stream in DDL, we need to provide Checkbox option showing the subjects related to the selected stream only. 现在,在选择DDL中的流时,我们需要提供“复选框”选项,以仅显示与所选流相关的主题。 But our entire SUBJECTS are in one COLUMN of another table. 但是我们的整个主题位于另一张表的一个列中。 How to retrieve only the Related subjects to the stream. 如何仅检索流中的相关主题。

Here is the aspx code: 这是aspx代码:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>

        <asp:DropDownList ID="ddlStream" runat="server" DataSourceID="SqlDataSource1" DataTextField="Branch_Name" DataValueField="Branch_Name" AutoPostBack="True" OnSelectedIndexChanged="ddlStream_SelectedIndexChanged">
        </asp:DropDownList>
        <br />
        <br />
        <asp:CheckBoxList ID="chkSubjects" runat="server" DataSourceID="SqlDataSource2" DataTextField="SUBJECT" DataValueField="SUBJECT">
        </asp:CheckBoxList>
        <br />
        <asp:GridView ID="GridView1" runat="server" AllowSorting="True" AutoGenerateColumns="False" DataSourceID="SqlDataSource2">
            <Columns>
                <asp:BoundField DataField="SUBJECT" HeaderText="SUBJECT" SortExpression="SUBJECT" />
            </Columns>
        </asp:GridView>
        <br />
        <br />
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ERPConnectionString %>"  SelectCommand="SELECT [Branch_Name] FROM [Branch_Master]"></asp:SqlDataSource>
        <br />
        <br />
        <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:ERPConnectionString %>" SelectCommand="SELECT [SUBJECT] FROM [Course_Master]"></asp:SqlDataSource>

    </div>
    </form>
</body>
</html>

All Subjects are in one Column and not in separate columns, that's what is causing the problem. 所有主题都在一个列中,而不是在单独的列中,这就是导致此问题的原因。 Do I need to create multiple columns based on STREAM? 我是否需要基于STREAM创建多个列? Cant this be done by only one common column for all SUBJECTS? 难道所有主题仅由一个公共列完成吗? I tried originally CONFIGURE Data Source option on extension of DDL and CheckBox, But it retrieves all data in the column. 我本来尝试在DDL和CheckBox扩展名上使用CONFIGURE Data Source选项,但它会检索列中的所有数据。

Thank you for helping me understand my question better and framing it better. 谢谢您帮助我更好地理解我的问题并更好地定性。 Do you need more input? 您需要更多输入吗?

Regards, Santosh 问候,桑托什

its simple .. 这很简单 ..

you have to use the selected index changed event of dropdownlist. 您必须使用下拉列表的选定索引更改事件。

  • assuming your dropdownlist name is ddlStream 假设您的下拉列表名称为ddlStream

  • assuming your checkboxlist name is chkStream 假设您的清单名称是chkStream

  • Set autopostback property of dropdownlist to TRUE. 将dropdownlist的autopostback属性设置为TRUE。

      protected void ddlStream_SelectedIndexChanged(object sender, EventArgs e) { SqlConnection Con = new SqlConnection("connectionString"); string query = "select [column name] from [table name] where [column name] ="+ddlStream.SelectedItem.Value; SqlCommand com = new SqlCommand(query, Con); chkStream.DataValueField = "Columnname"; chkStream.DataTextField = "Columnname"; conn.Open(); DataReader reader1 = comm.ExecuteReader(); chkStream.DataSource = reader1; chkStream.DataBind(); } 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何基于ASP.net Web表单中的下拉列表选择来更改按钮的颜色? - How to change the color of a button based on drop down list selection in ASP.net web forms? 在asp.net中创建带复选框的下拉菜单 - Creating Drop down with Check Box in asp.net 根据asp.net中的下拉列表选择更新图像 - Updating image based on drop down list selection in asp.net 如何根据另一个下拉列表 ASP.NET 的选择填充下拉列表 - How do I fill a drop down-list based on selection by another drop-down list ASP.NET asp.net中下拉列表的选定索引更改事件 - Selected Index change event of drop down list in asp.net 索引更改不起作用 asp.net 中的下拉列表 - On index change not working drop down list in asp.net ASP.NET C#将所选值从下拉列表输出更改为标签 - ASP.NET C# change selected value from drop down list output to label Asp.net下拉列表值在jquery对话框中未更改 - Asp.net drop down list value doesnt change within jquery dialog 有没有办法从asp.net MVC的另一个下拉列表中的先前选择中更改@ Html.DropDownList的值 - Is there a way to change the values of a @Html.DropDownList from a previous selection in another drop down list in asp.net MVC asp.net:设置为下拉列表选择的默认值 - asp.net : set default value selected for a drop down list
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM