Can you help me with this. I want this code to write a new row every time it encounters a new value of SphValue. I can add the </tr> tag to close the current row, but I can't write a new <tr> tag to open a new row. STUMPED!!!
@{
Page.Title = Request.QueryString["Description"];
Layout = "~/_SiteLayout.cshtml";
var dbSource = Database.Open("VisionWarehouse");
string searchTerm = @Request.QueryString["Description"];
string selectGridCommand ="SELECT * FROM tblLenses WHERE (Description = @0) ORDER BY SphBase, CylAdd";
var selectedGridData = dbSource.Query(selectGridCommand, searchTerm);
}
Thanks for the response. I'm afraid that doesn't help, however. At the point where I'm closing the current <tr> tag, I need a new row. There's only one open <tr> tag, so when I close it, I should be able to add a new <tr> tag. However, when I do, the
closing brackets no longer match up with their corresponding opening brackets.
BTW, sorry for the double-post and the formatting of the code. I haven't figured out how to paste code in here without the "double spacing" of lines. Also, none of the comments is in the actual code.
Here is the relevant section of the last post in a little more concise form.
<div class="Product Grid">
<Form name="frmProductOrder">
<table class="ProductDisplayGrid">
@{
<tr> <!---- open first row of table -->
@for (i = 0; i<= CylValues; i++)
{
<th> @CylMax </th> <!---- Write each header -->
CylMax = (CylMax - 0.25);
}
</tr><tr> <!---- Close first row, open next row -->
@foreach (var rec in selectedGridData)
{
<td><input name="@rec["LeftOPC"]"></td>
<td><input name="@rec["RightOPC"]"></td> <!---- Write inputs till we get to a new value of SphValue -->
if (SphValue != (float) @rec["SphBase"])
{
SphValue = (float) @rec["SphBase"];
</tr> <!---- Close the current row (here's where a new row is needed) -->
} <!---- if (SphValue...) closing bracket -->
} <!---- foreach closing bracket-->
} <!---- Should (and does) match up with the bracket beginning this code section -->
Do you mean enclose each rec in a pair of div tags? Maybe if you snipped the code where you mean to place the div tags and show me what you are suggesting.
<table>
<tbody>
// Now you can enclose them in divs. Note I am not using table in div because its not necessary.
<tr>
<div>
// Here should be the loop.
</div>
</tr>
</tbody>
</table>
I have only used one loop. You can try out others
Please "Marks As Answer" if any answer helped you out!
~~! FIREWALL !~~
Marked as answer by Angie xu - MSFT on Feb 05, 2013 01:01 AM
cestes001
Member
12 Points
41 Posts
Can't start a new tr tag inside a loop!!
Jan 24, 2013 09:30 PM|LINK
Can you help me with this. I want this code to write a new row every time it encounters a new value of SphValue. I can add the </tr> tag to close the current row, but I can't write a new <tr> tag to open a new row. STUMPED!!!
@{
Page.Title = Request.QueryString["Description"];
Layout = "~/_SiteLayout.cshtml";
var dbSource = Database.Open("VisionWarehouse");
string searchTerm = @Request.QueryString["Description"];
string selectGridCommand ="SELECT * FROM tblLenses WHERE (Description = @0) ORDER BY SphBase, CylAdd";
var selectedGridData = dbSource.Query(selectGridCommand, searchTerm);
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
<h1>@Request.QueryString["Description"]</h1>
<div class="Product Grid">
<Form name="frmProductOrder">
<table class="ProductDisplayGrid">
@{
double CylMin = 100;
double CylMax = -100;
int CylValues = 0;
double SphMin = 100;
double SphMax = -100;
int SphValues = 0;
float SphValue = 1000;
int i = 0;
foreach (var item in selectedGridData)
{
if (item["CylAdd"] < CylMin) {CylMin = (item["CylAdd"]);}
if (item["CylAdd"] > CylMax) {CylMax = item["CylAdd"];}
if (item["SphBase"] < SphMin) {SphMin = item["SphBase"];}
if (item["SphBase"] > SphMax) {SphMax = item["SphBase"];}
}
CylValues = (int) ((CylMax - CylMin)/0.25);
SphValues = (int) ((SphMax - SphMin)/0.25);
<tr>
@for (i = 0; i<= CylValues; i++)
{
<th> @CylMax </th>
CylMax = (CylMax - 0.25);
}
</tr><tr>
@foreach (var rec in selectedGridData)
{
<td><input name="@rec["LeftOPC"]"></td>
<td><input name="@rec["RightOPC"]"></td>
if (SphValue != (float) @rec["SphBase"])
{
SphValue = (float) @rec["SphBase"];
</tr> <-----right here, WebMatrix won't let me add a new <tr> tag. GRRRRRR!!!
}
}
</tr>
}
</table>
</Form>
</div>
</body>
</html>
saeed_saedva...
Member
408 Points
74 Posts
Re: Can't start a new tr tag inside a loop!!
Jan 25, 2013 04:19 AM|LINK
That's because you are creating a <tr> tag into another <tr> tag and this is wrong.
Saeed Saedvand
cestes001
Member
12 Points
41 Posts
Re: Can't start a new tr tag inside a loop!!
Jan 29, 2013 04:21 PM|LINK
Thanks for the response. I'm afraid that doesn't help, however. At the point where I'm closing the current <tr> tag, I need a new row. There's only one open <tr> tag, so when I close it, I should be able to add a new <tr> tag. However, when I do, the closing brackets no longer match up with their corresponding opening brackets.
BTW, sorry for the double-post and the formatting of the code. I haven't figured out how to paste code in here without the "double spacing" of lines. Also, none of the comments is in the actual code.
Here is the relevant section of the last post in a little more concise form.
<div class="Product Grid">
<Form name="frmProductOrder">
<table class="ProductDisplayGrid">
@{
<tr> <!---- open first row of table -->
@for (i = 0; i<= CylValues; i++)
{
<th> @CylMax </th> <!---- Write each header -->
CylMax = (CylMax - 0.25);
}
</tr><tr> <!---- Close first row, open next row -->
@foreach (var rec in selectedGridData)
{
<td><input name="@rec["LeftOPC"]"></td>
<td><input name="@rec["RightOPC"]"></td> <!---- Write inputs till we get to a new value of SphValue -->
if (SphValue != (float) @rec["SphBase"])
{
SphValue = (float) @rec["SphBase"];
</tr> <!---- Close the current row (here's where a new row is needed) -->
} <!---- if (SphValue...) closing bracket -->
} <!---- foreach closing bracket-->
} <!---- Should (and does) match up with the bracket beginning this code section -->
Afzaal.Ahmad...
Contributor
2661 Points
1040 Posts
Re: Can't start a new tr tag inside a loop!!
Jan 30, 2013 09:31 AM|LINK
The error would be maybe because you are adding a <tr> but you are not ending the line and ending the for loop.
Because every <tr> opened should be closed inside that container!
~~! FIREWALL !~~
cestes001
Member
12 Points
41 Posts
Re: Can't start a new tr tag inside a loop!!
Jan 30, 2013 04:20 PM|LINK
Thank you for your response.
It didn't help to place a closing tr tag outside the loop to close up the last row. I am still not allowed to open a new row.
Afzaal.Ahmad...
Contributor
2661 Points
1040 Posts
Re: Can't start a new tr tag inside a loop!!
Jan 30, 2013 04:54 PM|LINK
Why don't you just close the loops in a div than close them inside <tr>?
~~! FIREWALL !~~
cestes001
Member
12 Points
41 Posts
Re: Can't start a new tr tag inside a loop!!
Jan 30, 2013 05:33 PM|LINK
Thanks again.
Do you mean enclose each rec in a pair of div tags? Maybe if you snipped the code where you mean to place the div tags and show me what you are suggesting.
Afzaal.Ahmad...
Contributor
2661 Points
1040 Posts
Re: Can't start a new tr tag inside a loop!!
Jan 31, 2013 08:18 AM|LINK
Yes, I mean enclose them all in div tags like
I have only used one loop. You can try out others
~~! FIREWALL !~~