Click here to Skip to main content
15,890,557 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi I want to display a popup message displaying the details of the person when I click on the particular row either in script or code behind.

Note:Without Using any button to display

HTML
<pre>$(document).on("click",  function () {
                $("#id").html($(".EmpId", $(this).closest("tr")).html());
                $("#name").html($(".EmpName", $(this).closest("tr")).html());
                $("#add").html($(".add", $(this).closest("tr")).html());
                $("#dialog").dialog({
                    title: "View Details",
                    buttons: {
                        Ok: function () {
                            $(this).dialog('close');
                        }
                    },
                    modal: true
                });
                return false;
            });
    </script>


What I have tried:

C#
<pre> <div id="dialog" style="display: none">
    Id: <span id="id"></span>
    <br />
    Name: <span id="name"></span>
    <br />
    Department: <span id="Department"></span>
                <br />
    Age: <span id="Age"></span>
                <br />
    Salary: <span id="Salary"></span>
</div>
Posted
Updated 20-Feb-17 3:29am

1 solution

try this

protected void Page_Load(object sender, EventArgs e) {
           if (!this.IsPostBack)
           {
               DataTable dt = new DataTable();
               dt.Columns.Add("Id");
               dt.Columns.Add("Name");
               dt.Columns.Add("Description");
               dt.Rows.Add(1, "Apple", "a fruit");
               dt.Rows.Add(2, "Ball", "an object");
               dt.Rows.Add(3, "Cat", "meow");
               dt.Rows.Add(4, "Dog", "bow wow");
               GridView1.DataSource = dt;
               GridView1.DataBind();
           }

       }



<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
    <script src="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.9/jquery-ui.js" type="text/javascript"></script>
    <link href="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.9/themes/start/jquery-ui.css"
        rel="stylesheet" type="text/css" />
    <script type="text/javascript">
        $(function () {
            var grid = document.getElementById('<%= GridView1.ClientID%>');
        $('tr', grid).on('click', function () {
            $("#id").html($(".Id", $(this).closest("tr")).html());
            $("#name").html($(".Name", $(this).closest("tr")).html());
            $("#description").html($(".Description", $(this).closest("tr")).html());
            $("#dialog").dialog({
                title: "View Details",
                buttons: {
                    Ok: function () {
                        $(this).dialog('close');
                    }
                },
                modal: true
            });
        });
    });

    
    </script>


ASP.NET
<asp:GridView ID="GridView1" HeaderStyle-BackColor="#3AC0F2" HeaderStyle-ForeColor="White"
                runat="server" AutoGenerateColumns="false">
                <Columns>
                    <asp:BoundField DataField="Id" ItemStyle-CssClass="Id" HeaderText="Id" ItemStyle-Width="30" />
                    <asp:BoundField DataField="Name" ItemStyle-CssClass="Name" HeaderText="Name" ItemStyle-Width="150" />
                    <asp:BoundField DataField="Description" ItemStyle-CssClass="Description" HeaderText="Description"
                        ItemStyle-Width="150" />
                    
                </Columns>
            </asp:GridView>
            <div id="dialog" style="display: none">
                Id: <span id="id"></span>
                <br />
                Name: <span id="name"></span>
                <br />
                Description: <span id="description"></span>
            </div>


slightly modified from this based on your question.
 
Share this answer
 
v2
Comments
Member 12605293 20-Feb-17 13:00pm    
Hi Karthik
Thanks yu
Karthik_Mahalingam 20-Feb-17 13:34pm    
welcome :)
Member 12605293 21-Feb-17 0:29am    
Hi Karthik
I am using Itemtemplate instead of boundfield and it is not working :(
Karthik_Mahalingam 21-Feb-17 0:30am    
post the gridview markup
Karthik_Mahalingam 21-Feb-17 0:52am    
i have added this
<asp:GridView ID="GridView1" HeaderStyle-BackColor="#3AC0F2" HeaderStyle-ForeColor="White"
runat="server" AutoGenerateColumns="false">
<columns>
<asp:BoundField DataField="Id" ItemStyle-CssClass="Id" HeaderText="Id" ItemStyle-Width="30" />
<asp:BoundField DataField="Name" ItemStyle-CssClass="Name" HeaderText="Name" ItemStyle-Width="150" />

<asp:BoundField DataField="Description" ItemStyle-CssClass="Description" HeaderText="Description"
ItemStyle-Width="150" />
<asp:templatefield>
<itemtemplate>
<asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("Description") %>'>







stil working fine.

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