Please refer this code.
HTML
<%@ Register TagPrefix="cc1" Namespace="AjaxControlToolkit" Assembly="AjaxControlToolkit" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
<style type="text/css">
.modalPopup
{
background-color: #FFFFFF;
border-width: 3px;
border-style: solid;
border-color: black;
padding-top: 10px;
padding-left: 10px;
width: 300px;
height: 50x;
}
</style>
<style type="text/css">
body
{
font-family: Arial;
font-size: 10pt;
}
table
{
border: 1px solid #ccc;
}
table th
{
background-color: #F7F7F7;
color: #333;
font-weight: bold;
}
table th, table td
{
padding: 5px;
border-color: #ccc;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<cc1:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</cc1:ToolkitScriptManager>
<asp:GridView ID="GridView1" runat="server" OnRowDataBound="GridView1_RowDataBound"
AutoGenerateColumns="false">
<Columns>
<asp:TemplateField HeaderText="Id">
<ItemTemplate>
<asp:Label ID="lblId" Text='<%# Eval("ID") %>' runat="server"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Name">
<ItemTemplate>
<asp:Label ID="lblName" Text='<%# Eval("Name") %>' runat="server"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Number">
<ItemTemplate>
<asp:Label ID="lblNumber" Text='<%# Eval("Number") %>' runat="server"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Email">
<ItemTemplate>
<asp:Label ID="lblEmail" Text='<%# Eval("Email") %>' runat="server"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Address">
<ItemTemplate>
<asp:Label ID="lblAddress" runat="server" style="cursor:pointer;"></asp:Label>
<asp:Panel ID="pnlDemo" CssClass="modalPopup" runat="server">
<asp:Label ID="lblLongAddress" Text='<%# Eval("Address") %>' runat="server"></asp:Label>
</asp:Panel>
<cc1:HoverMenuExtender ID="hmeDemo" runat="server" PopupControlID="pnlDemo" HoverDelay="500"
PopupPosition="Right" TargetControlID="lblAddress">
</cc1:HoverMenuExtender>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Country" HeaderText="Country" />
</Columns>
</asp:GridView>
</div>
</form>
</body>
</html>
Namespace
using System.Data;
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
this.PopulateGrid();
}
}
private void PopulateGrid()
{
DataTable dt2 = new DataTable();
dt2.Columns.AddRange(new DataColumn[6]{
new DataColumn("ID", typeof(int)),
new DataColumn("Name", typeof(string)),
new DataColumn("Number", typeof(int)),
new DataColumn("Email", typeof(string)),
new DataColumn("Address", typeof(string)),
new DataColumn("Country", typeof(string)) });
dt2.Rows.Add(1, "Jake", 12, "1@1.com", "Asha Apartment 402/4th floor,Malad(W),Mumbai", "India");
dt2.Rows.Add(1, "Jhon", 32, "3@3.com", "Doodh Wala Complex A wing 202/2nd floor,Mumbai Central East,Mumbai", "India");
GridView1.DataSource = dt2;
GridView1.DataBind();
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
string address = ((Label)e.Row.Cells[5].FindControl("lblLongAddress")).Text;
int length = address.Length;
if (length > 15)
{
string shortAddress = address.Substring(0, 15);
shortAddress += " .....";
(e.Row.Cells[5].FindControl("lblAddress") as Label).Text = shortAddress;
}
}
}
Screenshot
