|
-
Jun 14th, 2004, 10:08 AM
#1
Thread Starter
Fanatic Member
display different value based on repeater value [RESOLVED]
I am using a repeater in asp.net to display some data. One of my fields is a 0 or 1 value. If a 0 is the value I want to display 'NO' and 1 would display 'YES'.
Is this possible with a repeater?
My code is below and field RA_ON is the field that returns 0 or 1 :
VB Code:
.......
<ASP:Repeater runat="server" DataSource='<%# dsFullList.DefaultView %>'>
<ItemTemplate>
<tr>
<td><%# dsFullList.FieldValue("ID", Container) %> </td>
<td><%# dsFullList.FieldValue("Name", Container) %> </td>
<td><%# dsFullList.FieldValue("RA_ON", Container) %> </td>
<td><%# dsFullList.FieldValue("ENTRY_DT", Container) %> </td>
</tr>
</ItemTemplate>
</ASP:Repeater>
.....
Last edited by lleemon; Jun 18th, 2004 at 02:32 PM.
-
Jun 14th, 2004, 11:18 AM
#2
PowerPoster
You can either call a method from within your item template for the value or you could hook into the ItemDataBound event and set the value from there.
-
Jun 17th, 2004, 09:41 AM
#3
I wonder how many charact
Llemon, as Lethal suggested, you can call it from the aspx page or from your .vb code.
I'd suggest calling it from vb code, only because it helps seperate design from function.
VB Code:
<ASP:Repeater runat="server" DataSource='<%# dsFullList.DefaultView %>'>
<ItemTemplate>
<tr>
<td><asp:Label runat="server" id="lblID"></asp:Label></td>
<td><asp:Label runat="server" ud="lblName"></asp:Label> </td>
<td><asp:Label runat="server id="lblRA_On"></asp:Label></td>
<td><asp:Label runat="server" id="lblENTRY_DT"></asp:Label> </td>
</tr>
</ItemTemplate>
</ASP:Repeater>
VB Code:
Private Sub yourRepeater_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles yourRepeater.ItemDataBound
If (e.Item.ItemType = ListItemType.Item) OrElse _
(e.Item.ItemType = ListItemType.AlternatingItem) Then
Dim dbr As System.Data.Common.DbDataRecord = CType(e.Item.DataItem, System.Data.Common.DbDataRecord)
Dim x As Label
x = DirectCast(e.Item.Controls("lblID"), Label)
x.Text = dbr(1).ToString
x = DirectCast(e.Item.Controls(3), Label)
x.Text = dbr("Name").ToString
x = DirectCast(e.Item.Controls(5), Label)
If dbr("RA_ON") = 0 Then
x.Text = "NO"
Else
x.Text = "YES"
End If
x = DirectCast(e.Item.Controls(7), Label)
x.Text = dbr("ENTRY_DT")
End If
End Sub
Notice how you can call controls by their name or index... the index may be different depending if you have a table in your repeater or not... etc..
-
Jun 17th, 2004, 03:50 PM
#4
Thread Starter
Fanatic Member
Well, I ended up going away with the repeater and going with a datagrid.
It works so I am happy.
Thanks to all that helped.
VB Code:
<%@ Page Language="VB" ContentType="text/html" ResponseEncoding="iso-8859-1" debug="true"%>
<%@ Import Namespace="System.Data.SqlClient" %>
<script runat="server">
Sub Page_Load
'----------------------------------------
'
'----------------------------------------
Dim conPubs As SqlConnection
Dim cmdSelect as SqlCommand
conPubs = New SqlConnection("Network Library=DBMSSOCN;Data Source=xx.xx.xxx.xx;Initial Catalog=mydatabase;User ID=myID;Password=myPassword")
cmdSelect = New SqlCommand("SELECT * FROM dbo.MYTABLENAME", conPubs)
conPubs.Open()
dgrdIP.DataSource = cmdSelect.ExecuteReader()
dgrdIP.DataBind()
conPubs.Close()
End Sub
Function ChangeToText(input as String) as String
'----------------------------------------
'
'----------------------------------------
'See if the number is 0
If Int32.Parse(input) = 0 Then
Return "ON"
Else
Return "OFF"
End If
End Function
Function FindDateDiff(incDate as DateTime) as String
'----------------------------------------
'
'----------------------------------------
Dim dtNow as DateTime
dtNow = DateTime.Now
Dim iHourDiff as Integer
iHourDiff= DateDiff(DateInterval.Hour, incDate, dtNow)
If iHourDiff > 0 Then
Return "<font color=""#FF0000"">offline</font>"
Else
Return "<b>online</b>"
End if
End Function
</script>
<html>
<head>
<title>IP List</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<form action="" method="post" name="frmCurrentIPs" id="frmCurrentIPs"></table>
<asp:datagrid ID="dgrdIP" ShowHeader="true" AutoGenerateColumns="false" runat="server" >
<columns>
<asp:boundcolumn HeaderText="ID" DataField="ID" />
<asp:boundcolumn HeaderText="IP" DataField="IP" />
<asp:boundcolumn HeaderText="HOSTNAME" DataField="HOSTNAME" />
<asp:templatecolumn HeaderText="RA_ON">
<itemtemplate>
<table border="0">
<tr>
<td>
<%# ChangeToText(DataBinder.Eval(Container.DataItem, "RA_ON")) %>
</td>
</tr>
</table>
</itemtemplate>
</asp:templatecolumn>
<asp:boundcolumn HeaderText="ENTRY_DT" DataField="ENTRY_DT" />
<asp:templatecolumn HeaderText="Status">
<itemtemplate>
<table border="0">
<tr>
<td>
<%# FindDateDiff(DataBinder.Eval(Container.DataItem, "ENTRY_DT")) %>
</td>
</tr>
</table>
</itemtemplate>
</asp:templatecolumn>
</columns>
</asp:datagrid>
<br>
Current Server Time is:
<% Response.Write(DateTime.Now) %>
</form>
</body>
</html>
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|