var op=document.createElement("option") //新建option
op.setAttribute("value",0) // 设置value
op.appendChild(document.createTextNode("请选择---")) //text
sel.appendChild(op) // 为select添加option
这样就可以给select添加option了
你说的是下拉框控件吗? 不知道要的是不是这样的在HTML是select控件
在 Winform应该是comboBox吧
//returnTable()这个方法里返回DataTable类型表格,里面有“id”和"procName"列
DataTable dt= returnTable()
this.comboBox1.DataSource = dt
this.comboBox1.ValueMember = "id"
this.comboBox1.DisplayMember = "procName"
在Webform应该是dropdownList 写在Load方法里
con.Open()
SqlCommand cmd = new SqlCommand(strSql,con)
SqlDataReader dr = cmd.ExecuteReader()
while (dr.Read())
{
DropDownList1.Items.Add(new ListItem(dr["status"].ToString(), dr["status_Id"].ToString()))
}
你可以先在设计器里手动添加,然后在Designer.cs里找到相应代码剪切过来就行,如下private System.Windows.Forms.ToolStrip toolStrip1
private System.Windows.Forms.ToolStripDropDownButton toolStripButton1
private System.Windows.Forms.ToolStripMenuItem aAAToolStripMenuItem
private System.Windows.Forms.ToolStripMenuItem aAAAToolStripMenuItem
private System.Windows.Forms.ToolStripMenuItem bBBToolStripMenuItem
private System.Windows.Forms.ToolStripMenuItem cCCToolStripMenuItem
public Form1()
{
InitializeComponent()
this.toolStrip1 = new System.Windows.Forms.ToolStrip()
this.toolStripButton1 = new System.Windows.Forms.ToolStripDropDownButton()
this.aAAToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem()
this.bBBToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem()
this.cCCToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem()
this.aAAAToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem()
this.Controls.Add(toolStrip1)
//
// toolStrip1
//
this.toolStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.toolStripButton1})
this.toolStrip1.Location = new System.Drawing.Point(0, 0)
this.toolStrip1.Name = "toolStrip1"
this.toolStrip1.Size = new System.Drawing.Size(617, 25)
this.toolStrip1.TabIndex = 3
this.toolStrip1.Text = "toolStrip1"
//
// toolStripButton1
//
this.toolStripButton1.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image
this.toolStripButton1.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.aAAToolStripMenuItem,
this.bBBToolStripMenuItem,
this.cCCToolStripMenuItem})
this.toolStripButton1.ImageTransparentColor = System.Drawing.Color.Magenta
this.toolStripButton1.Name = "toolStripButton1"
this.toolStripButton1.Size = new System.Drawing.Size(29, 22)
this.toolStripButton1.Text = "toolStripButton1"
//
// aAAToolStripMenuItem
//
this.aAAToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.aAAAToolStripMenuItem})
this.aAAToolStripMenuItem.Name = "aAAToolStripMenuItem"
this.aAAToolStripMenuItem.Size = new System.Drawing.Size(152, 22)
this.aAAToolStripMenuItem.Text = "AAA"
//
// bBBToolStripMenuItem
//
this.bBBToolStripMenuItem.Name = "bBBToolStripMenuItem"
this.bBBToolStripMenuItem.Size = new System.Drawing.Size(152, 22)
this.bBBToolStripMenuItem.Text = "BBB"
//
// cCCToolStripMenuItem
//
this.cCCToolStripMenuItem.Name = "cCCToolStripMenuItem"
this.cCCToolStripMenuItem.Size = new System.Drawing.Size(152, 22)
this.cCCToolStripMenuItem.Text = "CCC"
//
// aAAAToolStripMenuItem
//
this.aAAAToolStripMenuItem.Name = "aAAAToolStripMenuItem"
this.aAAAToolStripMenuItem.Size = new System.Drawing.Size(152, 22)
this.aAAAToolStripMenuItem.Text = "AAAA"
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)