C# 二级下拉列表框联动(ComboBox)(ExecuteReader)

本文详细介绍了如何在C#中实现二级下拉列表框(ComboBox)的联动效果,通过ExecuteReader方法获取数据并展示。内容涵盖数据读取、控件交互及事件处理等关键步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace _02ProvinceCitySelect
{
    public partial class MainFrm : Form
    {
        public MainFrm()
        {
            InitializeComponent();
        }

        private void MainFrm_Load(object sender, EventArgs e)
        {
            //加载数据库中的所有的省的数据
            string connStr = ConfigurationManager.ConnectionStrings["sqlConn"].ConnectionString;

            //创建链接对象
            using (SqlConnection conn =new SqlConnection(connStr))
            {
                using (SqlCommand cmd =conn.CreateCommand())
                {
                    conn.Open();//***********8
                    cmd.CommandText =@"select AreaId, AreaName, Ar
<asp:TemplateColumn HeaderText="Plant" HeaderStyle-HorizontalAlign="center"> <ItemStyle CssClass="dxgv"></ItemStyle> <ItemTemplate> <asp:Label ID="lb_week_p" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.PLANTKEY") %>'> </asp:Label> </ItemTemplate> <FooterTemplate> <font face="宋体"></font> <asp:DropDownList ID="ddl_week_p" runat="server" Width="100px" AutoPostBack="true"> <asp:ListItem Selected="True" Value="">----</asp:ListItem> </asp:DropDownList> </FooterTemplate> <EditItemTemplate> <asp:DropDownList ID="ddl_e_week_p" ToolTip='<%# DataBinder.Eval(Container, "DataItem.PLANTKey") %>' OnSelectedIndexChanged="ddl_e_week_p_SelectedIndexChanged" AutoPostBack="true"runat="server" Width="100px"> </asp:DropDownList> <asp:Label ID="lb_week_p_edit" Visible="false" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.PLANTKEY") %>'></asp:Label> </EditItemTemplate> </asp:TemplateColumn> <asp:TemplateColumn HeaderText="Storage Location" HeaderStyle-HorizontalAlign="center"> <ItemStyle CssClass="dxgv"></ItemStyle> <ItemTemplate> <asp:Label ID="lb_week_s" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.STORAGE_LOCATIONKEY") %>'> </asp:Label> </ItemTemplate> <FooterTemplate> <font face="宋体"></font> <asp:DropDownList ID="ddl_week_s" runat="server" Width="90px"> <asp:ListItem Selected="True" Value="">----</asp:ListItem> </asp:DropDownList> </FooterTemplate> <EditItemTemplate> <asp:DropDownList ID="ddl_e_week_s" ToolTip='<%# DataBinder.Eval(Container, "DataItem.STORAGE_LOCATIONKey") %>' runat="server" Width="90px"> </asp:DropDownList> <asp:Label ID="lb_week_s_edit" Visible="false" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.STORAGE_LOCATIONKEY") %>'></asp:Label> </EditItemTemplate> </asp:TemplateColumn> protected void ddl_week_p_SelectedIndexChanged(object sender, EventArgs e) { DropDownList item = (DropDownList)((Control)sender).Parent.Parent.FindControl("ddl_week_s"); item.DataTextField = "txt";
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值