Hi Team,
In View Page, Based on HTML table row click , corresponding data’s are binding to labels.
But when page loads , initially labels are empty and if click HTML table row it is binding perfectly.
How to make HTML table first row as selected one and binding the same to labels in page load itself.
This is the coding i used to get the data on row click. This need to reflect on pageload without rowclick for first row in HTML table.
Let me know how to achieve this.
Thanks in advance.
function getdata() {
var table = document.getElementById("tbl_ProjectDetails");
var rows = table.rows;
$("#tbl_ProjectDetails tbody").delegate("tr", "click", function (e) {
var f0 = document.getElementById('lblActivityCode');
var f1 = document.getElementById('txtPROJECTFROMDATE');
var f2 = document.getElementById('txtPROJECTTODATE');
var arr = $('#tbl_ProjectDetails').dataTable().fnGetData($(this));
f0.innerHTML = (arr[0]).replace(/<\/?span[^>]*>/g, "");
f1.innerHTML = (arr[1]).replace(/<\/?span[^>]*>/g, "");
f2.innerHTML = (arr[2]).replace(/<\/?span[^>]*>/g, "");
});
}
<table class="table table-striped table-bordered table-hover" id="tbl_ProjectDetails">
<thead>
<tr>
<th>ActivityCode</th>
<th>FromDate</th>
<th>ToDate</th>
<th class="noExl"></th>
</tr>
</thead>
<tbody>
@foreach (var item in ViewBag.ActivityDetails)
{
<tr>
<td><span>@item.ActivityCode</span></td>
<td><span>@item.PROJECTFROMDATE</span></td>
<td><span>@item.PROJECTTODATE</span></td>
<td class="noExl">
<button type="button" class="btn btn-warning" onclick="getdata();">Details</button>
</td>
</tr>
}
</tbody>
</table>