ASP.NET 4.0中的下拉列表 [英] Dropdown list in ASP.NET 4.0

查看:80
本文介绍了ASP.NET 4.0中的下拉列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨朋友们,



其实我的疑问是,如何在用sps填充ddl之后将新文本添加到ddl中?



让我问清楚,



i填充了角色表中的数据到下拉列表..

但仍然我想把--ALL--项添加到ddlst怎么样?



如何通过c#编码将--ALL-- item添加到ddslt?



等待回复

hi friends,

actually my doubt is, how to add new text into ddl after populate the ddl by sps?

let i ask clearly,

i was populate the datas from rolemaster table in to dropdownlist..
but still i wanna add --ALL-- item to ddlst how?

how to add --ALL-- item to ddslt by c# coding?

am waiting for as soon as reply

推荐答案

Dropdownlist1.Items.Insert(0, - ALL - );



在从collection / db绑定值之后添加如下。
Dropdownlist1.Items.Insert(0,"-ALL-");

Add like this after binding values from collection/db.


C#:

C#:
DataSet ds;

DataTable dt;

DataRow newRow;

// get the drop down values from the SP as a dataset
ds = webService.getMyDDLValues();

// now add the values to the drop down list
if ((ds.Tables.Count > 0) && (ds.Tables[0].Rows.Count > 0))
{
        // grab the table from the dataset
        dt = ds.Tables[0];

        // create the new row
        newRow = dt.NewRow();

    // specify the select item's value
        newRow["SELECT_VALUE"] = "-1";

        // specify the text to show in the drop down
        neRow["SELECT_TEXT"] = "--ALL--";

    // add the row at position 0
        dt.Rows.InsertAt(newRow, 0);

        // now bind the table to the control
        myDDL.DataSource = dt;
        myDDL.DataBind();
}





ASP.NET:



ASP.NET:

<asp:DropDownList CssClass="myDDLClass" ID="myDDL" DataValueField="SELECT_VALUE" DataTextField="SELECT_TEXT" runat="server" ></asp:DropDownList>


这篇关于ASP.NET 4.0中的下拉列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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