如何在asp.net网页中的combobox中动态添加项目 [英] How to add items dynamically in combobox in asp.net web page

查看:99
本文介绍了如何在asp.net网页中的combobox中动态添加项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是ASP.Net的新手。我创建了一个包含3个字段的简单网页。



1.电子邮件(下拉列表/组合框)

2.文件上传按钮

3.备注 - 正常文本框



目前我在该下拉列表中有4封电子邮件,我将来如何添加一封或多封电子邮件在下拉列表中动态显示...?



注意:电子邮件之前只能添加下拉列表中已提及的人员。



请建议我......继续进行..

I am very new to ASP.Net. And I am creation a simple web page that contains 3 fields.

1. Email (dropdownlist/combobox)
2. File upload button
3. Remarks -Normal textbox

Currently I have 4 emails in that dropdown list, how can I add one or more emails in future dynamically in the drop downlist...?

Note : The emails can add only the people who are all already mentioned in the dropdown list before.

Please suggest me...to proceed further..

推荐答案

先生,请关注绑定下拉列表 [ ^ ]链接并引用该链接。将新的emailid存储在数据库中,并在存储该电子邮件后将该数据重新绑定到下拉列表中,或者您可以编写Response.redirect(您的页面名称)。这将重新打开您的网站/页面并重新绑定数据..



在页面加载中写下拉式绑定代码。



Sir please Follow Bind dropdown list[^] link and refer that link. Store that new emailid in database and after storing that email rebind that data in dropdown list or you can write Response.redirect(yourpage name). that will re open your site/page and rebind data..

Write dropdown binding code in page load.

protected void Page_Load(object sender, EventArgs e)
{
  bindtoddl();
}

private void bindtoddl()
    {
         SqlConnection con = new SqlConnection(s);
        SqlCommand cmd = new SqlCommand("select FieldName from TableName", con);
        SqlDataAdapter sda = new SqlDataAdapter(cmd);
        DataSet ds = new DataSet();
        sda.Fill(ds);
        DropDownList1.DataSource = ds;
        DropDownList1.DataTextField = "Email";
        DropDownList1.DataValueField = "ID";
        DropDownList1.DataBind();

      }                            


这篇关于如何在asp.net网页中的combobox中动态添加项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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