Skip to content

Add items to dropdown menu

Sandhya Bhosale

Asked Oct 27, 2006, 10:19 PM EDT2 answers
Share
LinkedInX
There is a dropdownlist where in the items are added dynamically.

However, there is an item "All Messages" that is to be added so that when a user selects "All Messages" from the DropDown List, it will displays all the items along with their information in datagrid.

But if user selects a single item, all that item and its information will be reflected in the datagrid.

My problem, is how can I make "All Messages" appear first in the dropdown list so that the user sees only "All Messages" in the Dropdown list when he views the datagrid and then can select a particular item of his choice later on.

The code I have written is :


SqlConnection conn = new SqlConnection(ConnectionString);

SqlDataAdapter additemsda = new SqlDataAdapter("select Newsletter_Topic from Admin_Add_Newsletter_Topic", conn);

conn.Open();

DataSet additemsds = new DataSet();

additemsda.Fill(additemsds, "Admin_Add_Newsletter_Topic");

DataTable additemsdt = new DataTable();

additemsdt = additemsds.Tables["Admin_Add_Newsletter_Topic"];

DataRow[] additemsdr = new DataRow[additemsdt.Rows.Count];

additemsdr = additemsdt.Select();

ArrayList Article = new ArrayList();

if (additemsdr.Length != 0)

{

Article_Grp = additemsdr[0]["Newsletter_Topic"].ToString();

for (int i = 0; i < additemsdr.Length; i++)

{

Article.Add(additemsdr[i]["Newsletter_Topic"].ToString());

}

ddlType.DataSource = Article;

ddlType.DataBind();

ddlType.Items.Add("All Messages");

}

conn.Close();


Please help

2 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • Mahesh Chand
    0

    Try InsertAt(0, "All Messages") method after data is loaded or add "All Messsages" to your data soruce (DataSet or DataTable) dynamically.

    0
  • 0
    Thank you. The solution worked.
    0