I have a data table that contains some values for Certifications. This table can be updated in a different part of my application. On the web page I am currently working on, I would like to have check boxes appear for every value in the data table. I
have been struggling with this trying to use a For Each loop and I cannot get it to work for anything. Any suggestions?
I am using the following Razor syntax to obtain my data (I know this works because I can display it in a WebGrid):
@{
var
db = Database.Open("MyConn");
var
sql = "SELECT CertDesc FROM Certification ORDER BY CertDesc";
Actually it was missing a } but I fixed that and it worked great. Thanks! I don't know why I was spinning my wheels on this ... I think I just lose patience. Thanks!!
LSNelson
Member
1 Points
4 Posts
Checkboxes from data table
Aug 18, 2010 09:14 PM|LINK
I have a data table that contains some values for Certifications. This table can be updated in a different part of my application. On the web page I am currently working on, I would like to have check boxes appear for every value in the data table. I have been struggling with this trying to use a For Each loop and I cannot get it to work for anything. Any suggestions?
I am using the following Razor syntax to obtain my data (I know this works because I can display it in a WebGrid):
@{
var db = Database.Open("MyConn");
var sql = "SELECT CertDesc FROM Certification ORDER BY CertDesc";
var data = db.Query(sql);
}
Mikesdotnett...
All-Star
154808 Points
19853 Posts
Moderator
MVP
Re: Checkboxes from data table
Aug 18, 2010 10:06 PM|LINK
How about:
@{foreach (var item in data){
<input type="checkbox" name="@item.CertDesc" value="@item.CertDesc" /> @item.CertDesc <br />
}
Beginning ASP.NET Web Pages with WebMatrix | My Site | Twitter
LSNelson
Member
1 Points
4 Posts
Re: Checkboxes from data table
Aug 18, 2010 10:10 PM|LINK
Actually it was missing a } but I fixed that and it worked great. Thanks! I don't know why I was spinning my wheels on this ... I think I just lose patience. Thanks!!