I am just beginner at Web Pages and have followed through the Tutorials.
I can return the data from the database, but suspect there must be a better way then writing separate queries for the Grid and the Header, as I want to add radio buttions that will display values from the database.
Can I use the just the one query with all the columns and use just one column in the Grid, and another for my Heading, etc.
@{Layout ="~/Shared/_SiteLayout.cshtml";
Page.Title ="MyPage";
var
db = Database.Open("MyDb");
var
pageId = Request.QueryString["page"];
<!--
Return data for the Grid -->
var
selectedData = db.Query("SELECT
Expectation FROM Questions order by SubHeading");
var
grid = newWebGrid(source:
selectedData, rowsPerPage: 1, canSort: false);
<!--
Return Sub Heading Title above Grid -->
var
GridHeading = ("SELECT
Question_Heading FROM Questions where SubHeading = (case when @0 is null then 1 else @0 end)");
var
SubHeading = db.QueryValue(GridHeading, pageId);}
MickEgan
Member
3 Points
3 Posts
Displaying Data from a Database
Jul 23, 2012 11:39 PM|LINK
I am just beginner at Web Pages and have followed through the Tutorials.
I can return the data from the database, but suspect there must be a better way then writing separate queries for the Grid and the Header, as I want to add radio buttions that will display values from the database.
Can I use the just the one query with all the columns and use just one column in the Grid, and another for my Heading, etc.
@{Layout ="~/Shared/_SiteLayout.cshtml";
Page.Title ="MyPage";
var db = Database.Open("MyDb");
var pageId = Request.QueryString["page"];
<!-- Return data for the Grid -->
var selectedData = db.Query("SELECT Expectation FROM Questions order by SubHeading");
var grid = new WebGrid(source: selectedData, rowsPerPage: 1, canSort: false);
<!-- Return Sub Heading Title above Grid -->
var GridHeading = ("SELECT Question_Heading FROM Questions where SubHeading = (case when @0 is null then 1 else @0 end)");
var SubHeading = db.QueryValue(GridHeading, pageId);}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Audit</title>
</head>
<body>
<div><!-- Return Sub Heading above Grid -->
<h1>@SubHeading</h1>
<!-- Creates the Grid -->
@grid.GetHtml(tableStyle:"grid",
headerStyle:"head",
alternatingRowStyle:"alt",
columns: grid.Columns(grid.Column("Expectation")))
</div>
</body>
</html>
MickEgan
Member
3 Points
3 Posts
Re: Displaying Data from a Database
Aug 21, 2012 11:49 AM|LINK
worked this out by doing more tutorials