insert the item in dynamicaly binded dropdownlist

This code demonstrate how to insert the item in dynamically binded dropdownlist

Ds is the Object of dataset, ds contains the Stakeowner and Stakeowner Id

            ddlStakeOwner.DataSource = ds;
            ddlStakeOwner.DataTextField = "StakeOwner";
            ddlStakeOwner.DataValueField = "StakeOwnerId";

            ddlStakeOwner.Items.Insert(0, "Select Stake owner");

            ddlStakeOwner.Items[0].Text = "Select Stake owner";
            ddlStakeOwner.Items[0].Value = "0";
            ddlStakeOwner.Items.Insert(ds.Rows.Count + 1, "Others");
            ddlStakeOwner.Items[ds.Rows.Count + 1].Text = "Others";
            ddlStakeOwner.Items[ds.Rows.Count + 1].Value = "Others";
%d bloggers like this: