如何在C#.net的下拉列表底部添加选择 [英] How to add select at bottom of dropdownlist in c#.net

查看:150
本文介绍了如何在C#.net的下拉列表底部添加选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我需要在dropdownlist中绑定数据库值.

我的代码是:-

Hi,

I need to bind the database values in dropdownlist.

My code is:-

c.cmd1 = new SqlCommand("select Policy_Id,PolicyName from PolicyBoard", c.con);
       SqlDataReader dr1;
       c.con.Open();
       dr1 = c.cmd1.ExecuteReader();
       ddlfile.DataSource = dr1;
       ddlfile.DataTextField = "PolicyName";
       ddlfile.DataValueField = "Policy_Id";
       ddlfile.DataBind();
       ddlfile.Items.Insert(0, "---Select---");
       dr1.Close();
       c.con.Close();



***************

下拉菜单在顶部显示选择值.
但我需要在底部显示该选择

在此先感谢

Sucharitha



***************

Dropdown shows the select value at top.
But i need to display that Select at bottom

Thanks in advance

Sucharitha

推荐答案

更改以下语句

change the below statement

ddlfile.Items.Insert(0, "---Select---");



对此.



to this..

ddlfile.AppendDataBoundItems=true;
ddlfile.Items.Add("---Select---");


您还可以使用数据表来绑定数据,就像这样

you can also bind data using data table also like this

con.open();
 SqlDataAdapter adp = new SqlDataAdapter("select Policy_Id,PolicyName from PolicyBoard", con);

                DataTable tab = new DataTable();
                adp.Fill(tab);
                

ddlfile.DataSource = tab;
        ddlfile.DataTextField = "PolicyName";
        ddlfile.DataValueField = "Policy_Id";
        ddlfile.DataBind();
        ddlfile.Items.Insert(0, "---Select---);
        ddlfile.Items.Insert(tab.Rows.Count, "---Select---);



希望对您有帮助



Hope this will help you


这篇关于如何在C#.net的下拉列表底部添加选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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