I have a Drop Down List
. I need the value of my DDL
when the index changes.So i do this :
private void CMBGroup_SelectedIndexChanged(object sender, EventArgs e)
{
int id=int.Parse(CMBGroup.SelectedValue.ToString());
//do something with id
}
In form load
i fetch my data :
goodGroups=objGoodGroupRepositoy.GetAll().ToList();
CMBGroup.DataSource = goodGroups;
CMBGroup.ValueMember = "Id";
CMBGroup.DisplayMember = "Name";
I have such data in my database :
id serial name
1 121 g1
2 123 g2
But i got this error before loading my form :
Input string was not in a correct format
I got this error in here in indexchange
event of DDL
int id=int.Parse(CMBGroup.SelectedValue.ToString());
The model :
public partial class GoodGroup
{
public GoodGroup()
{
this.Goods = new HashSet<Good>();
}
public int Id { get; set; }
public string Serial { get; set; }
public string Name { get; set; }
public virtual ICollection<Good> Goods { get; set; }
}