Help in repeater

P

Prakash

Hi,
I have a repeater control for bind data from databse.
Using table with in this control, I am displaying data.

<# DataBinder.Eval(Container.DataItem, "Name") %>

I need to check a particular column for null when It
display. if it is null, then it will not be display in
control.

How can i check the database column in repeater control?

Please help

With regards,
Prakash.
 
M

Mike Moore [MSFT]

Hi Prakash,

You can do this by calling a function rather than using DataBinder.Eval.
Here is a sample based on the pubs database. It shows all last names
normally except for the last name "Bennet" which it replaces with just the
letter "b".

<asp:Repeater id="Repeater1" runat="server">
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "au_id") %>
&nbsp;
<%# GetValue(Container.DataItem("au_lname")) %>
<br>
</ItemTemplate>
</asp:Repeater>


Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
Bind()
End If
End Sub

Private Sub Bind()
Dim Qry1 As System.Data.SqlClient.SqlDataReader
Dim connectionString As String = "server='localhost';
trusted_connection=true; Database='pubs'"
Dim sqlConnection As System.Data.SqlClient.SqlConnection = New
System.Data.SqlClient.SqlConnection(connectionString)
Dim queryString As String = "SELECT au_id, au_lname, au_fname FROM
authors"
Dim sqlCommand As System.Data.SqlClient.SqlCommand = New
System.Data.SqlClient.SqlCommand(queryString, sqlConnection)
sqlConnection.Open()
Qry1 =
sqlCommand.ExecuteReader(System.Data.CommandBehavior.CloseConnection)
Repeater1.DataSource = Qry1
Repeater1.DataBind()
Qry1.Close()
sqlCommand.Dispose()
sqlConnection.Close()
sqlConnection.Dispose()
End Sub

Protected Function GetValue(ByVal OldVal As String) As String
If OldVal = "Bennet" Then
Return "b"
Else
Return OldVal
End If
End Function


I hope this helps.

Thank you, Mike
Microsoft, ASP.NET Support Professional

Microsoft highly recommends to all of our customers that they visit the
http://www.microsoft.com/protect site and perform the three straightforward
steps listed to improve your computer’s security.

This posting is provided "AS IS", with no warranties, and confers no rights.


--------------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
474,079
Messages
2,570,573
Members
47,205
Latest member
ElwoodDurh

Latest Threads

Top