Hi.
I think you should bind your DropDownList to a proper datasource, not use
DataSource='<%#Eval("age")%>'
.
Maybe this will help (from
MSDN[
^]):
<asp:DropDownList id="ColorList"
AutoPostBack="True"
OnSelectedIndexChanged="Selection_Change"
runat="server"/>
void Selection_Change(Object sender, EventArgs e)
{
}
But more importantly:
void Page_Load(Object sender, EventArgs e)
{
if(!IsPostBack)
{
ColorList.DataSource = CreateDataSource();
ColorList.DataTextField = "ColorTextField";
ColorList.DataValueField = "ColorValueField";
ColorList.DataBind();
ColorList.SelectedIndex = 0;
}
}
And
ICollection CreateDataSource()
{
DataTable dt = new DataTable();
dt.Columns.Add(new DataColumn("ColorTextField", typeof(String)));
dt.Columns.Add(new DataColumn("ColorValueField", typeof(String)));
dt.Rows.Add(CreateRow("White", "White", dt));
dt.Rows.Add(CreateRow("Silver", "Silver", dt));
dt.Rows.Add(CreateRow("Dark Gray", "DarkGray", dt));
dt.Rows.Add(CreateRow("Khaki", "Khaki", dt));
dt.Rows.Add(CreateRow("Dark Khaki", "DarkKhaki", dt));
DataView dv = new DataView(dt);
return dv;
}
DataRow CreateRow(String Text, String Value, DataTable dt)
{
DataRow dr = dt.NewRow();
dr[0] = Text;
dr[1] = Value;
return dr;
}
In
CreateDataSource()
you can read the values from file or the DataGrid and assign them to a datasource.