I have table which create by dynamically (store procedure return Datatable) and create successfully but when I click click event getTrnDetails(batchno)
then I want to color <tr>
for show separate other row. How can I do this?
Razor Template
@foreach (DataRow row in opType.Rows) {
sl = 1;
<tr>
@foreach (DataColumn column in opType.Columns) {
string batchno = @row[column.ColumnName].ToString();
<td>
@if (sl == 1) {
<i class="fas fa-eye mr-1"
@onclick="(()=>getTrnDetails(batchno))"
style="cursor: pointer;"></i>
} @row[column.ColumnName]
</td>
sl = sl + 1;
}
</tr>
}
2
Answers
You can work with JavaScript code.
Provide a unique id to each
<tr>
element.Pass the
<tr>
id when calling thegetTrnDetails
function.Call the JavaScript function via
JS.InvokeVoidAsync
function with therowIndex
parameter.Implement your JS function in the index.html or separate JS file(s) (but make sure you need to attach to the index.html). Add the CSS class to the
<tr>
elementYou could try using a dictionary to store the selected state of the row.
You can create a dictionary where the key is the unique identifier of the row and the value is a boolean value indicating whether the row is selected, and then initialize it to the unselected state.Here is an example you can use as a reference:
Change selected status:
Return to selected state:
foreach: