在按钮单击事件的下拉列表中添加列表项 [英] Add the Listitems in dropdownlist on button click event

查看:74
本文介绍了在按钮单击事件的下拉列表中添加列表项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何显示和添加SqlTable列值作为<列表项>在按钮单击下拉列表中的事件

解决方案

嗨曼尼什,
在button_Click上编写以下代码:-

受保护的 void  Button1_Click(对象发​​件人,System.EventArgs e)
{
   ListBox1.Items.Add( ListItem(" " )));
   ListBox1.Items.Add( ListItem(" " )));
   //  ListBox1是ListBox控件的ID.
 }


这是ASP.NET的示例,其中有一个列表框,一个DropDownList和一个按钮.

 受保护的 无效 Button1_Click(对象发​​件人,EventArgs e)
        {
             foreach (ListItem项目 in  ListBox1.Items)
            {
                DropDownList1.Items.Add(item.Text);
                DropDownList1.Items [DropDownList1.Items.Count- 1 ].Value = item.Value;
            }
        } 


客户端编码

 <  ![CDATA [<%@    页面   语言  ="     AutoEventWireup   ="       CodeFile   ="    继承  ="     > ]]> 


How to show&Add SqlTable column value as a <list item> in dropdownlist on button click event

解决方案

Hi Manish,
On button_Click write following code:-

Protected void Button1_Click (object sender, System.EventArgs e)
{
   ListBox1.Items.Add(new ListItem("Carbon", "C"));
   ListBox1.Items.Add(new ListItem("Oxygen", "O"));
   //ListBox1 is the ID of ListBox Control.
 }


This is an example for ASP.NET where you have a List Box, a DropDownList and a Button.

protected void Button1_Click(object sender, EventArgs e)
        {
            foreach (ListItem item in ListBox1.Items)
            {
                DropDownList1.Items.Add(item.Text);
                DropDownList1.Items[DropDownList1.Items.Count - 1].Value = item.Value;
            }
        }


Client Coding

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


这篇关于在按钮单击事件的下拉列表中添加列表项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆