本人初学,以前没什么编程经验,只做个网管,熟悉系统.现在为了生存没办法,30岁的人了,开始学ASP.NET.这年头家里有孩有妻.不容易
希望能结交一些有经验的朋友我想学这东西,可能主要是实践.我想这么学,先做个实例.
比如插入.
首先是文本的插入成功了,然后加DropDownList就不知道怎么弄了,因为这个部门,我想做成选择行的

解决方案 »

  1.   

    直接拖个dropdownList设置一下就OK 了
      

  2.   

    首先佩服您的學習精神!
    文本插入成功后,使用SQL語句把該文本取出來,存入DataTable,然后,設置DropDownList的DataTextField和DataValueField,然后Bind即可.
      

  3.   

    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Web;
    using System.Web.SessionState;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;
    using Inserte;namespace itsystem1
    {
    /// <summary>
    /// WebForm1 的摘要说明。
    /// </summary>
    public class WebForm1 : System.Web.UI.Page
    {
    protected System.Web.UI.WebControls.TextBox t1;
    protected System.Web.UI.WebControls.TextBox t3;
    protected System.Web.UI.WebControls.TextBox t4;
    protected System.Web.UI.WebControls.Label Label1;
    protected System.Web.UI.WebControls.Label Label2;
    protected System.Web.UI.WebControls.Label Label3;
    protected System.Web.UI.WebControls.Label Label4;
    protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator1;
    protected System.Web.UI.WebControls.DropDownList t2;
    protected System.Web.UI.WebControls.Button btn1;

    private void Page_Load(object sender, System.EventArgs e)
    {
    // 在此处放置用户代码以初始化页面
    } #region Web 窗体设计器生成的代码
    override protected void OnInit(EventArgs e)
    {
    //
    // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
    //
    InitializeComponent();
    base.OnInit(e);
    }

    /// <summary>
    /// 设计器支持所需的方法 - 不要使用代码编辑器修改
    /// 此方法的内容。
    /// </summary>
    private void InitializeComponent()
    {    
    this.t4.TextChanged += new System.EventHandler(this.t4_TextChanged);
    this.btn1.Click += new System.EventHandler(this.btn1_Click);
    this.Load += new System.EventHandler(this.Page_Load); }
    #endregion private void t4_TextChanged(object sender, System.EventArgs e)
    {

    } private void btn1_Click(object sender, System.EventArgs e)
    {
    string itname=t1.Text;
    string itdep=t2.Text;
    string itaddress=t3.Text;
    string itque=t4.Text;
    Data d=new Data();

    bool falg=d.Insert(itname,itdep,itaddress,itque);
    if(falg)
    {
    Response.Write("添加成功");
    }
    else
    {
    Response.Write("添加失败");
    } }
    }
    }
      

  4.   

    <%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="itsystem1.WebForm1" %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
    <HTML>
    <HEAD>
    <title>WebForm1</title>
    <meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
    <meta content="C#" name="CODE_LANGUAGE">
    <meta content="JavaScript" name="vs_defaultClientScript">
    <meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
    </HEAD>
    <body MS_POSITIONING="GridLayout">
    <form id="Form1" method="post" runat="server">
    <asp:textbox id="t1" style="Z-INDEX: 101; LEFT: 56px; POSITION: absolute; TOP: 216px" runat="server"></asp:textbox><asp:textbox id="t3" style="Z-INDEX: 102; LEFT: 184px; POSITION: absolute; TOP: 336px" runat="server"></asp:textbox><asp:textbox id="t4" style="Z-INDEX: 103; LEFT: 536px; POSITION: absolute; TOP: 304px" runat="server"
    TextMode="MultiLine" Width="200px" Height="80px"></asp:textbox><asp:label id="Label1" style="Z-INDEX: 104; LEFT: 8px; POSITION: absolute; TOP: 216px" runat="server">姓  名</asp:label><asp:label id="Label2" style="Z-INDEX: 105; LEFT: 392px; POSITION: absolute; TOP: 216px" runat="server">部  门</asp:label><asp:label id="Label3" style="Z-INDEX: 106; LEFT: 96px; POSITION: absolute; TOP: 336px" runat="server">联系方式</asp:label><asp:label id="Label4" style="Z-INDEX: 107; LEFT: 480px; POSITION: absolute; TOP: 336px" runat="server">问  题</asp:label><asp:button id="btn1" style="Z-INDEX: 108; LEFT: 504px; POSITION: absolute; TOP: 416px" runat="server"
    Text="提交"></asp:button>
    <asp:DropDownList id="t2" style="Z-INDEX: 109; LEFT: 464px; POSITION: absolute; TOP: 208px" runat="server">
    <asp:ListItem Value="IT部">IT部</asp:ListItem>
    <asp:ListItem Value="行政部">行政部</asp:ListItem>
    <asp:ListItem Value="研发部">研发部</asp:ListItem>
    <asp:ListItem Value="商务部">商务部</asp:ListItem>
    <asp:ListItem Value="客服部">客服部</asp:ListItem>
    <asp:ListItem Value="产品部">产品部</asp:ListItem>
    </asp:DropDownList>
    <asp:RequiredFieldValidator id="RequiredFieldValidator1" style="Z-INDEX: 110; LEFT: 224px; POSITION: absolute; TOP: 216px"
    runat="server" ErrorMessage="必填你的名字" ControlToValidate="t1"></asp:RequiredFieldValidator></form>
    </body>
    </HTML>
      

  5.   

    using System;
    using System.Data;
    using System.Data.SqlClient;
    namespace Inserte
    {
    /// <summary>
    /// Data 的摘要说明。
    /// </summary>
    public class Data
    {
    SqlConnection conn=new SqlConnection("server=appleii;database=itsys;user=sa;pwd=overmax2005");
    public bool Insert (string itname,string itdep,string itaddress,string itque)
    {
    if(itname!=""&itdep!=""&itaddress!=""&itque!="")
    { string sql="insert into itinfo (itname,itdep,itaddress,itque) values (@itname,@itdep,@itaddress,@itque)";
    SqlCommand comm=new SqlCommand(sql,conn);
    comm.Parameters.Add("@itname",SqlDbType.Char).Value=itname;
    comm.Parameters.Add("@itdep",SqlDbType.Char).Value=itdep;
    comm.Parameters.Add("@itaddress",SqlDbType.Char).Value=itaddress;
    // comm.Parameters.Add("@itque",SqlDbType.Char).Value=itque;
    comm.Parameters.Add("@itque",SqlDbType.Char).Value=itque; conn.Open();
    comm.ExecuteNonQuery();
    conn.Close();
    return true;
    }
    else
    {
    return false;
    }
    }
    }
    }