Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi I have tried to restrict the popup on empty text box ,and buttons inside the grid using jquey.

What I have tried:

JavaScript
<pre>$(function () {
            var grid = document.getElementById('<%= gvDetails.ClientID%>');
            $('tr', grid).on('click', function () {
                $("#id").html($(".clsempid", $(this).closest("tr")).html());
                $("#name").html($(".clsempid1", $(this).closest("tr")).html());
                $("#department").html($(".clsempid2", $(this).closest("tr")).html());
                $("#age").html($(".clsempid3", $(this).closest("tr")).html());
                $("#sal").html($(".clsempid4", $(this).closest("tr")).html());
                $("#dialog").dialog({
                    title: "View Details",
                    buttons: {
                        Ok: function () {
                            $(this).dialog('close');
                        }
                    },
                     modal: true
                });
            });
        });
Posted
Updated 21-Feb-17 1:09am
Comments
Karthik_Mahalingam 21-Feb-17 6:35am    
post the mark up.
Member 12605293 21-Feb-17 6:46am    
<asp:GridView ID="gvDetails" style="background-color:lightgreen; border-collapse: collapse;
background-color: lightgreen;
margin-top: -53px;" DataKeyNames="EmpId,EmpName" runat="server"
OnPageIndexChanging="OnPaging"
AutoGenerateColumns="false" HeaderStyle-BackColor="#61A6F8"
ShowFooter="true" HeaderStyle-Font-Bold="true" HeaderStyle-ForeColor="White"
CellPadding="10" CellSpacing="0"
AllowPaging="true" PageSize="5"
AllowSorting="True" OnRowDataBound="gvDetails_OnRowDataBound"
OnRowCancelingEdit="gvDetails_RowCancelingEdit"
OnRowDeleting="gvDetails_RowDeleting" OnRowEditing="gvDetails_RowEditing"
OnRowUpdating="gvDetails_RowUpdating"
OnRowCommand="gvDetails_RowCommand" OnSelectedIndexChanged="OnSelectedIndexChanged">

<Columns >


<asp:TemplateField HeaderText="EmployeeID">
<itemtemplate>
<asp:Label ID="lblempid" runat="server" class="clsempid"
Text='<%# Eval("EmpId")%>'>

<footertemplate>
<asp:TextBox ID="txtempid"
MaxLength="5" runat="server">
<asp:RequiredFieldValidator ID="rfvempid" runat="server" ControlToValidate="txtempid" Text="*" ValidationGroup="validaiton" />





<asp:TemplateField HeaderText="EmployeeName">
<edititemtemplate>
<asp:TextBox ID="txtempname" runat="server" Text='<%#Eval("EmpName") %>' />

<itemtemplate>
<asp:Label ID="lblempname" runat="server" class="clsempid1" Text='<%#Eval("EmpName") %>' />

<footertemplate>
<asp:TextBox ID="txtempname1" runat="server" onkeypress=" return onlyAlphabets(event,this);" />
<asp:RequiredFieldValidator ID="rfvempname" runat="server" ControlToValidate="txtempname1" Text="*" ValidationGroup="validaiton" />




<asp:TemplateField HeaderText="Department">
<edititemtemplate>
<asp:TextBox ID="txtdep" runat="server" Text='<%#Eval("Dep") %>' />

<itemtemplate>
<asp:Label ID="lbldep" runat="server" class="clsempid2" Text='<%#Eval("Dep") %>' />

<footertemplate>
<asp:TextBox ID="txtdep1" runat="server" />
<asp:RequiredFieldValidator ID="rfvdep" runat="server" ControlToValidate="txtdep1" Text="*" ValidationGroup="validaiton" />




<asp:TemplateField HeaderText="Age">
<headertemplate>
Age






<edititemtemplate>
<asp:TextBox ID="txtage" runat="server" Text='<%#Eval("Age") %>' />

<itemtemplate>
<asp:Label ID="lblage" runat="server" class="clsempid3" Text='<%#Eval("Age") %>' />

<footertemplate
Karthik_Mahalingam 21-Feb-17 6:49am    
button code?
post the code inside code tag

<code> your html
Member 12605293 21-Feb-17 6:48am    
If I click on edititemtemplate it shows the box with empty value. and I don't want that box to get displayed on that template.
Karthik_Mahalingam 21-Feb-17 6:51am    
does it post back on click of edit button ?

1 solution

try this

$('tr', grid).on('click', function (obj, b) {
             if (['Update', 'Edit', 'Add'].indexOf(obj.target.value) > -1)
                 return;
 
Share this answer
 
Comments
Member 12605293 21-Feb-17 7:23am    
I have tried it is not working
Member 12605293 21-Feb-17 7:24am    
$(function () {

var grid = document.getElementById('<%= gvDetails.ClientID%>');
$('tr', grid).on('click', function (obj,b) {
if (['Update', 'Edit', 'Add', 'txtsal1','Cancel'].indexOf(obj.target.value) > -1)
return false;

$("#id").html($(".clsempid", $(this).closest("tr")).html());
$("#name").html($(".clsempid1", $(this).closest("tr")).html());
$("#department").html($(".clsempid2", $(this).closest("tr")).html());
$("#age").html($(".clsempid3", $(this).closest("tr")).html());
$("#sal").html($(".clsempid4", $(this).closest("tr")).html());
$("#dialog").dialog({
title: "View Details",
buttons: {
Ok: function () {
$(this).dialog('close');
}
},
modal: true
});

});

});
Karthik_Mahalingam 21-Feb-17 7:54am    
alert this value and check
alert(obj.target.value)
Member 12605293 21-Feb-17 8:11am    
Not working Karthik
Karthik_Mahalingam 21-Feb-17 8:13am    
what is the meaning of Not working?
what does it alerts?

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