Click here to Skip to main content
14,300,474 members
Rate this:
Please Sign up or sign in to vote.
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

Rate this:
Please Sign up or sign in to vote.

Solution 1

Hi Parazival,

You can encapsulate the click event in the Document Ready function, like this-:
<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.
   
v2

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100