I have one following table html, the data of rows in the table is looped by foreach.
Can I use Razor to get the value of each row into a List or an array in C#?
My C# code Razor (I tried this so far)
#{
var l = new List<string>();
l.Add(#<input id="updated_value2" data-bind="value:value,visible:isEditing()" />);
}
Here's my table
<table class="table table-hover">
<tbody data-bind="foreach: $root.mapJsons(parameters())">
<tr class="data-hover">
<td>
<strong>
<span data-bind="text:key" />
</strong>
</td>
<td>
#*display label and input for dictionary<value> false DIS true APP*#
<input id="updated_value" data-bind="value:value,visible:isEditing()" />
<label id="display_value" data-bind="text:value,visible:!isEditing()" />
</td>
</tr>
</tbody>
<thead>
<tr>
<th style="width: 30%">
Name
</th>
<th style="width: 30%">
Value
</th>
<th></th>
</tr>
</thead>
</table>
Your foreach loop is being executed client-side (looks like a KnockoutJS binding?) rather than server-side, so any Razor code you embed in the table is only going to be called once as it's rendered by the server. So the answer is no, you cannot populate a server-side list with this particular foreach loop.
Related
I am currently working on a project where I want to show a column of a related record (form a sql database). For some of my table this works perfeclty fine, altough for one of them it does not. As shown below, there is no error and the record is filled in with the correct data, but it does not show up correclty. Can anyone help me with this? I tried updating my database already.
<table id="coaches">
<thead>
<tr>
<th>
</th>
<th>
#Html.DisplayNameFor(model => model.Picture)
</th>
<th></th>
</tr>
</thead>
<tbody>
#foreach (var item in Model) {
<tr>
<td>
<img src=#Html.DisplayFor(modelItem => item.Picture) class="person">
</td>
<td>
<div style="padding-left:10px">
<div class="name">#Html.DisplayFor(modelItem => item.Organization.Name)Should be here</div>
<div class="natclub">
<img src="https://dalto.nl/wp-content/uploads/2018/08/dalto-logo.png" class="emblem">
<br>
<img src="https://cdn.countryflags.com/thumbs/netherlands/flag-400.png" class="flag">
</div>
</div>
</td>
</tr>
}
</tbody>
</table>
Organization Table
Coaches table
Page in question
Thanks in advance!
I tried to release a new update of the database using the PM Console, but nothing changed.
I am starting to learn asp.net and I am a totally noob.
So, I am trying to select a town and, in the right side I should get the list of all town (like in the picture above).
So I am trying to do like, when I select a town from left side it should be mark as selected as from the right side.
My code is below
<table class="table datatable-responsive datatable-medical-map" id="medProviders" style="width:100%">
<thead>
<tr class="bg-info">
<th>Medical Provider (* Choose one)</th>
<th>Distance (miles)</th>
<th>Duration</th>
</tr>
</thead>
<tbody>
#{ int i = 0;
foreach (var item in medProviders)
{
<tr class="sortList" style="cursor:pointer" id="increment-#i" data-id="#item.Id" data-lat="#item.Latitude" data-long="#item.Longitude">
<td>#item.Firstname</td>
<td id="distance-#i"></td>
<td id="duration-#i"></td>
</tr>
i++;
}
}
</tbody>
</table>
<p id="medicalValidation"></p>
I need to print all the code under my question
if there is data in #store.GuaranteePolicy print all the <tr>. If there is no data, then print nothing.
No matter if there is data in or not in #store.GuaranteePolicy, then "Payment" is always printet, but why?
I said that if (store.GuaranteePolicy is different than null, then print)
The if statement is working with this:
If there is data in store.GuaranteePolicy everything is printed perfect
If there is no data in store.GuaranteePolicy the text is not printed, BUT the word Payment: is printed. So the whole <tr> is printed even if it is not true?
#if (store.GuaranteePolicy != null) {
<tr>
<th class="small-12 large-6 columns first">
<table>
<tr>
<th width="300">
<p class="text-left small-text-left"><strong>Payment:</strong></p>
</th>
</tr>
</table>
</th>
<th class="small-12 large-6 columns last">
<table>
<tr>
<th width="300">
<p class="text-left small-text-left">
<span>#store.GuaranteePolicy</span>
</p>
</th>
<th class="expander"></th>
</tr>
</table>
</th>
</tr>
}
If GuaranteePolicy is a collection try this:
#if(store.GuaranteePolicy != null && store.GuaranteePolicy.Count > 0)
{
}
if string:
#if(!string.IsNullOrWhiteSpace(store.GuaranteePolicy))
{
}
and so on...
I'm not a professional in C# and ASP.Net so please have some patience with me.
I have the following problem.
I'm using ASP.Net WebForm API with C# for creating a dashboard.
I have a generic HTML table (taken out from a sql query) which will be displayed. Now I want to implement the feature, that when the user clicks on a cell for example in the column ID, he should get an details view which is a bootstrap modal.
For that I need the ID value which is in this cell. How can I get this value?
With the value I will start a new sql query and more other specific informations are going to be shown.
Here is my aspx. structure:
<table id="MyTable" class="table table-striped table-bordered table-condensed table-responsive">
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Typ</th>
<th>Something else</th>
<th>Date</th>
</tr>
</thead>
<tbody>
<%=Tabelle.GetTable.dataTable_all%>
</tbody>
</table>
<script type="text/javascript">
$(document).ready(function () {
$('#MyTable').DataTable();
});
</script>
the variable dataTable_all is a string. So this is my table in HTML Code.
My Result for <tbody> is 366 rows big and here is an extract:
<tr>
<td>154789</td>
<td>Testproject X</td>
<td>Good</td>
<td>greencolored</td>
<td>01.01.2015</td>
</tr>
<tr>
<td>189365</td>
<td>Testproject B</td>
<td>Good</td>
<td>redcolored</td>
<td>08.01.2015</td>
</tr>
<tr>
<td>136471</td>
<td>Testproject Y</td>
<td>Bad</td>
<td>pinkcolored</td>
<td>15.04.2015</td>
</tr>
So how can I do it that when I click on for example ID 136471 that the value will be given to a variable in my c# code?
Change to:
<tr data-id="154789">
<td>154789</td>
<td>Testproject X</td>
<td>Good</td>
<td>greencolored</td>
<td>01.01.2015</td>
</tr>
<tr data-id="189365">
<td>189365</td>
<td>Testproject B</td>
<td>Good</td>
<td>redcolored</td>
<td>08.01.2015</td>
</tr>
<tr data-id="136471">
<td>136471</td>
<td>Testproject Y</td>
<td>Bad</td>
<td>pinkcolored</td>
<td>15.04.2015</td>
</tr>
Then use:
$('tbody tr').click(function() {
alert($(this).data('id'));
});
Working demo
https://jsfiddle.net/jknysneo/
I have this piece of html code. I want to get the text inside the <div> tag using WatiN. The C# code is below, but I'm pretty sure it could be done way better than my solution. Any suggestions?
HTML:
<table id="someId" cellspacing="0" border="1" style="border-collapse:collapse;" rules="all">
<tbody>
<tr>
<th scope="col"> </th>
</tr>
<tr>
<td>
<div>Some text</div>
</td>
</tr>
</tbody>
</table>
C#
// Get the table ElementContainer
IElementContainer diagnosisElementContainer = (IElementContainer)_control.GetElementById("someId");
// Get the tbody element
IElementContainer tbodyElementContainer = (IElementContainer)diagnosisElementContainer.ChildrenWithTag("tbody");
// Get the <tr> children
ElementCollection trElementContainer = tbodyElementContainer.ChildrenWithTag("tr");
// Get the <td> child of the last <tr>
IElementContainer tdElementContainer = (IElementContainer)trElementContainer.ElementAt<Element>(trElementContainer.Count - 1);
// Get the <div> element inside the <td>
Element divElement = tdElementContainer.Divs[0];
Based on the given, something like this is how I'd go for IE.
IE myIE = new IE();
myIE.GoTo("[theurl]");
string theText = myIE.Table("someId").Divs[0].Text;
The above is working on WatiN 2.1, Win7, IE9.