I created the following codes and commented inline so that you can understand how to bind data to a DropDownList and how to add an attribute to each item in the drop down list (Assuming that, you wanted to add an attribute to each item).
Here is the Drop-Down list in the aspx page:
<asp:DropDownList ID="ddlStatus" runat="server">
</asp:DropDownList>
And here is the code in the CodeBehind:
public partial class Default : System.Web.UI.Page
{
class Person
{
public string Name
{
get;
set;
}
public int Id
{
get;
set;
}
public Person(string Name, int Id)
{
this.Name = Name;
this.Id = Id;
}
}
protected void Page_Load(object sender, EventArgs e)
{
IList<Person> persons = new List<Person>();
persons.Add(new Person("John",1));
persons.Add(new Person("Tom",2));
persons.Add(new Person("Shubho",3));
ddlStatus.DataTextField = "Name";
ddlStatus.DataValueField = "Id";
ddlStatus.DataSource = persons;
ddlStatus.DataBind();
for (int i = 0; i < ddlStatus.Items.Count; i++)
{
ListItem item = ddlStatus.Items[i];
item.Attributes["SysCode"] = "Code-" + (i + 1).ToString();
}
}
}
And, following is the HTML markup that will be generated in the browser:
<select id="ddlStatus" name="ddlStatus">
<option syscode="Code-1" value="1">John</option>
<option syscode="Code-2" value="2">Tom</option>
<option syscode="Code-3" value="3">Shubho</option>
</select>
I hope, the example codes are self explanatory and you can understand how to implement your code.
I used an example class to bind data (Person). In reality you should retrieve data from the database and bind the data to the DropDownList using some kind of collections of object.