I'm using reflection to bind my TableAdapters
result in a dropdownlist
, just now, I'm using:
DropDownBinding.Bind<Cat_AgTableAdapter>(CbxAg, "Cod", "AgenV", Convert.ToInt32(CbxReg.SelectedValue));
public static void Bind<T>(DropDownList dropDown, string textField, string valueField, int filter, string method, bool defaultSelect) where T : new()
{
var type = typeof(T);
var typeMethod = type.GetMethod(method);
var clase = Activator.CreateInstance(type);
dropDown.DataSource = typeMethod.Invoke(clase, new object[] { filter });
dropDown.DataTextField = textField;
dropDown.DataValueField = valueField;
dropDown.DataBind();
if (defaultSelect)
dropDown.Items.Insert(0, new ListItem("-- Select an option--", "-1"));
}
But in the line: dropDown.DataSource = typeMethod.Invoke(clase, new object[] { filter });
is giving me the error:
Unable to cast object of type 'System.Int32' to type 'System.Byte'.
Aucun commentaire:
Enregistrer un commentaire