Click here to Skip to main content
15,891,607 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted

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

Add like this after binding values from collection/db.
 
Share this answer
 
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>
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900