by Dave
Mon 11 February 2008 @ 10:47
LINQ is awesome!
1: // Get the data from the database using LINQ
2: var topTen =
3: (from bl in lpcsql.Blogs
4: where bl.PostType == 1
5: orderby bl.ID descending
6: select bl).Take(10);
7: // Bind data to the repeater.
8: objBlog.DataSource = topTen;
9: objBlog.DataBind();
10: // Check if its me, and if so activate the Edit and Delete controls
11: if (User.IsInRole("Administrators"))
12: {
13: for (int post=0; post < objBlog.Items.Count; post++)
14: { Label lbl = (Label)objBlog.Items[post].FindControl("EditControl");
15: if (lbl.Visible == false)
16: lbl.Visible = true;
17: if (lbl.Enabled == false)
18: lbl.Enabled=true;
19: }
20: }
21: lpcsql.Connection.Close();