本文介绍了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
推荐答案
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中的下拉列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!