This way,
HTML:
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server" HeaderStyle-BackColor="#3AC0F2" HeaderStyle-ForeColor="White"
RowStyle-BackColor="#A1DCF2" OnRowDataBound="GridView1_RowDataBound" AlternatingRowStyle-BackColor="White"
AlternatingRowStyle-ForeColor="#000" Width="780" EmptyDataText="No data" AutoGenerateColumns="false">
<Columns>
<asp:BoundField DataField="ID" HeaderText="Name" />
<asp:BoundField DataField="Name" HeaderText="Name" />
<asp:BoundField DataField="Number" HeaderText="Number" />
<asp:BoundField DataField="Email" HeaderText="Email" />
<asp:BoundField DataField="Address" HeaderText="Address" ControlStyle-Width="30" />
<asp:TemplateField HeaderText="Address">
<ItemTemplate>
<asp:Label ID="lblAddress" runat="server"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Country" HeaderText="Country" />
</Columns>
</asp:GridView>
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 = e.Row.Cells[4].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;
}
}
}