zoukankan      html  css  js  c++  java
  • DropDownList控件学习

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Data.SqlClient;
    using System.Data;
    
    namespace WebApplication1
    {
        public partial class DropDownList控件 : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                if (!Page.IsPostBack)
                {
                    BindMonthList();
                    BindUserList();
                }
    
            }
            private void BindMonthList()
            {
                int[] monthList=new int[12];
                for (int i = 0; i <= 11; i++)
                {
                    monthList[i] = i + 1;
                }
                ddlMonthList.DataSource = monthList;
                ddlMonthList.DataBind();
    
            }
            private void BindUserList()
            {
                SqlConnection conn = new SqlConnection(@"server=Rose-PCSQLEXPRESS;Database=User;User Id=sa;password=");
                SqlCommand command = new SqlCommand("Select ID,RealName from UserInfo", conn);
                SqlDataAdapter adapter = new SqlDataAdapter(command);
                DataTable data = new DataTable();
                adapter.Fill(data);
    
                ddlUserList.DataTextField = "RealName";
                ddlUserList.DataValueField = "ID";
                ddlUserList.DataSource = data;
                ddlUserList.DataBind();
    
            }
    
        }
    }
    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="DropDownList控件.aspx.cs" Inherits="WebApplication1.DropDownList控件" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
           <asp:DropDownList ID="ddlMonthList" runat="server">
           </asp:DropDownList>
           <asp:DropDownList ID="ddlUserList" runat="server">
           </asp:DropDownList>
        </div>
        </form>
    </body>
    </html>


     

  • 相关阅读:
    nodejs之express路由与动态路由
    nodejs之mongodb操作
    nodejs之路由
    nodejs之简单应用与运行
    nodejs之fs 模块
    nodejs 之简单web服务器
    C++之结构体struct
    STL之stack
    【剑指offer】05替换空格,C++实现
    【剑指offer】04A二维数组中的查找,C++实现
  • 原文地址:https://www.cnblogs.com/ai394495243/p/3343505.html
Copyright © 2011-2022 走看看