Question

I have a Radio Bullet List, i want to set the values and text of this radio list using LINQ, but return "0" when the first value on database is "1".

at the database i have two columns, codcategoria and dsccategoria, i want define value of radio_bullet_list with codcategoria and the display text with dsccategoria

testesiteEntities db = new testesiteEntities();//create object

//select object
rblCategoria.DataValueField = db.categoria.Select( c => c.codcategoria ).ToString(); 
rblCategoria.DataTextField = db.categoria.Select(dc => dc.dsccategoria).ToString();
rblCategoria.DataBind();//define valores no bullet list

what is wrong?

Was it helpful?

Solution

The DataValueField and DataTextField are both just looking for string representation of what they're supposed to use. You would set your DataSource to some sort of IEnumerable that actually has those properties, so assuming db.categoria has the properties "codcategoria" and "dsccategoria" you could do something like:

testesiteEntities db = new testesiteEntities();//create object

//select object
rblCategoria.DataValueField = "codcategoria"; 
rblCategoria.DataTextField = "dsccategoria";
rblCategoria.DataSource = db.categoria.Select().ToList();
rblCategoria.DataBind();//define valores no bullet list
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top