Hi Tevin,
Check this example. Now please take its reference and correct your code.
Database
For this example I have used of Northwind database that you can download using the link given below.
Download Northwind Database
Procedure
--EXEC [NorthWind_GetEmployees]
CREATE PROCEDURE [NorthWind_GetEmployees]
AS
BEGIN
SELECT [EmployeeId]
,[FirstName]
,[BirthDate]
FROM [Employees]
UNION
SELECT 10,'Rahul','01/01/1900'
END
HTML
<asp:Repeater ID="rpEmployees" runat="server" OnItemDataBound="OnItemDataBound">
<HeaderTemplate>
<table>
<tr>
<th>Employee Id</th>
<th>Name</th>
<th>Birth Date</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td><asp:Label ID="lblEmployeeId" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "EmployeeId")%>'></asp:Label></td>
<td><asp:Label ID="lblName" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "FirstName")%>'></asp:Label></td>
<td><asp:Label ID="lblDOB" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "BirthDate")%>'></asp:Label></td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
Namespaces
C#
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
VB.Net
Imports System.Data
Imports System.Data.SqlClient
Imports System.Configuration
Code
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
this.BindGrid();
}
}
private void BindGrid()
{
string conString = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection con = new SqlConnection(conString))
{
using (SqlCommand cmd = new SqlCommand("NorthWind_GetEmployees", con))
{
cmd.CommandType = CommandType.StoredProcedure;
con.Open();
this.rpEmployees.DataSource = cmd.ExecuteReader();
this.rpEmployees.DataBind();
con.Close();
}
}
}
protected void OnItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
RepeaterItem item = e.Item;
string birthDate = (item.FindControl("lblDOB") as Label).Text;
if (!string.IsNullOrEmpty(birthDate))
{
if (Convert.ToDateTime(birthDate) == Convert.ToDateTime("1/1/1900 12:00:00 AM"))
{
(item.FindControl("lblDOB") as Label).Text = string.Empty;
}
}
}
}
VB.Net
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not Me.IsPostBack Then
Me.BindGrid()
End If
End Sub
Private Sub BindGrid()
Dim conString As String = ConfigurationManager.ConnectionStrings("constr").ConnectionString
Using con As SqlConnection = New SqlConnection(conString)
Using cmd As SqlCommand = New SqlCommand("NorthWind_GetEmployees", con)
cmd.CommandType = CommandType.StoredProcedure
con.Open()
Me.rpEmployees.DataSource = cmd.ExecuteReader()
Me.rpEmployees.DataBind()
con.Close()
End Using
End Using
End Sub
Protected Sub OnItemDataBound(ByVal sender As Object, ByVal e As RepeaterItemEventArgs)
If e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType = ListItemType.AlternatingItem Then
Dim item As RepeaterItem = e.Item
Dim birthDate As String = TryCast(item.FindControl("lblDOB"), Label).Text
If Not String.IsNullOrEmpty(birthDate) Then
If Convert.ToDateTime(birthDate) = Convert.ToDateTime("1/1/1900 12:00:00 AM") Then
TryCast(item.FindControl("lblDOB"), Label).Text = String.Empty
End If
End If
End If
End Sub
Screenshot