Hi anand.mand,
Refer Below sample.
HTML
<asp:GridView ID="gvCity" runat="server" AutoGenerateColumns="false" OnRowDataBound="OnRowDataBound">
<Columns>
<asp:BoundField HeaderText="City" DataField="City" />
</Columns>
</asp:GridView>
Namespace
C#
using System.Data;
VB.Net
Imports System.Data
Code
C#
protected void Page_Load(object sender, EventArgs e)
{
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[] { new DataColumn("City") });
dt.Rows.Add("Mumbai(Maharastra)");
dt.Rows.Add("Banglore(Karnataka)");
gvCity.DataSource = dt;
gvCity.DataBind();
}
protected void OnRowDataBound(object sender, GridViewRowEventArgs e)
{
if(e.Row.RowType == DataControlRowType.DataRow)
{
TableCell cell = e.Row.Cells[0];
int index = cell.Text.IndexOf('(');
if(index >= 0)
{
cell.Text = cell.Text.Substring(0, index);
}
}
}
VB.Net
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
Dim dt As DataTable = New DataTable()
dt.Columns.AddRange(New DataColumn() {New DataColumn("City")})
dt.Rows.Add("Mumbai(Maharastra)")
dt.Rows.Add("Banglore(Karnataka)")
gvCity.DataSource = dt
gvCity.DataBind()
End Sub
Protected Sub OnRowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
If e.Row.RowType = DataControlRowType.DataRow Then
Dim cell As TableCell = e.Row.Cells(0)
Dim index As Integer = cell.Text.IndexOf("("c)
If index >= 0 Then
cell.Text = cell.Text.Substring(0, index)
End If
End If
End Sub
Result GridView