Show Hide Button based on condition using jQuery in ASP.Net

Last Reply 3 months ago By dharmendr

Posted 3 months ago

How to make button visible based on id in jquery?

<script type="text/javascript"> 
    var statusid="<%#Eval("statusid"%>

In this how to make button visible if statusid=50?



You are viewing reply posted by: dharmendr 3 months ago.
Posted 3 months ago


It is not possible to create sample with Telerik controls. So i have used ASP controls.

Check this example. Now please take its reference and correct your code.


<script type="text/javascript" src=""></script>
<script type="text/javascript">
    $(function () {
        $('[id*=GridView1] tr:not(:has(th))').each(function () {
            var id = $(this).find('[id*=lblId]').html().trim();
            if (id == 2) {
            } else {
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False">
        <asp:TemplateField HeaderText="Id">
                <asp:Label ID="lblId" runat="server" Text='<%# Eval("Id") %>'></asp:Label>
        <asp:TemplateField HeaderText="Name">
                <asp:Label ID="lblName" runat="server" Text='<%# Eval("Name") %>'></asp:Label>
        <asp:TemplateField HeaderText="Country">
                <asp:Label ID="lblCountry" runat="server" Text='<%# Eval("Country") %>'></asp:Label>
                <asp:Button ID="btnView" Text="View" runat="server" />



protected void Page_Load(object sender, EventArgs e)
    if (!this.IsPostBack)
        System.Data.DataTable dt = new System.Data.DataTable();
        dt.Columns.AddRange(new System.Data.DataColumn[] { 
                        new System.Data.DataColumn("Id", typeof(int)),
                        new System.Data.DataColumn("Name", typeof(string)),
                        new System.Data.DataColumn("Country",typeof(string)) });
        dt.Rows.Add(1, "John Hammond", "United States");
        dt.Rows.Add(2, "Mudassar Khan", "India");
        dt.Rows.Add(3, "Suzanne Mathews", "France");
        dt.Rows.Add(4, "Robert Schidner", "Russia");
        GridView1.DataSource = dt;


Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
    If Not Me.IsPostBack Then
        Dim dt As System.Data.DataTable = New System.Data.DataTable()
        dt.Columns.AddRange(New System.Data.DataColumn() {
                            New System.Data.DataColumn("Id", GetType(Integer)),
                            New System.Data.DataColumn("Name", GetType(String)),
                            New System.Data.DataColumn("Country", GetType(String))})
        dt.Rows.Add(1, "John Hammond", "United States")
        dt.Rows.Add(2, "Mudassar Khan", "India")
        dt.Rows.Add(3, "Suzanne Mathews", "France")
        dt.Rows.Add(4, "Robert Schidner", "Russia")
        GridView1.DataSource = dt
    End If
End Sub