Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I need to get the selected row Values when user clicks on view or Download button

thanks

What I have tried:

for (int i = 0; i < dt.Rows.Count; i++)
                {

htmlTable.Append("<table id='table' class='table table-hover group'>");
                    htmlTable.Append("<tbody>");
                    htmlTable.Append("<tr class='tb-background-clr'>");
                    htmlTable.Append("<td class='group'>");
                    htmlTable.Append("<h1>");
                    htmlTable.Append(dt.Rows[i]["Column1"].ToString());
                    htmlTable.Append("</h1>");
                    htmlTable.Append("<p>");
                    htmlTable.Append("Testing:" + dt.Rows[i]["Column2"].ToString() + "</p>");
                    htmlTable.Append("<button class='view-btn'>");
                    htmlTable.Append("VIEW</button>");
                    htmlTable.Append("<button class='view-btn1'>");
                    htmlTable.Append("DOWNLOAD</button>");
                    htmlTable.Append("</td>");
                    htmlTable.Append("<td class='group'>");
                    htmlTable.Append("<p class='month'>");
                    htmlTable.Append("" + date + "<br>" + Month.ToUpper() + " " + year + "");
                    htmlTable.Append("</p>");
                    htmlTable.Append("</td>");
                    htmlTable.Append("<td>");
                    htmlTable.Append(dt.Rows[i]["Column3"].ToString());
                    htmlTable.Append("</td>");
                    htmlTable.Append("</tr>");
                    htmlTable.Append("</tbody>");
                    htmlTable.Append("</table>");
                    ltTable.Text = htmlTable.ToString();

}

--**-- notworking
<script>
<pre>$("#table tr").click(function(){
   $(this).addClass('selected').siblings().removeClass('selected');    
   var value=$(this).find('td:first').html();
   alert(value);    
});



<pre>td {border: 1px #DDD solid; padding: 5px; cursor: pointer;}</pre>

--**--
Posted
Updated 8-Sep-19 23:18pm
v3

1 solution

Hi Parazival,

You can encapsulate the click event in the Document Ready function, like this-:
JavaScript
<script>
$(document).ready(function() {
$("#table tr").click(function(){
   $(this).addClass('selected').siblings().removeClass('selected');    
   var value=$(this).find('td:first').html();
   alert(value);    
});
}
</script>

I hope this will work.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900