473,402 Members | 2,055 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 software developers and data experts.

Beginner question

Hi all

I'm very new to dotNet and just trying to get my head around the right way
to do the thing that I would normally do in asp.

In asp I would loop through a recordset and output all the html dynamically
for the layout I want. I have seen some examples of
using a repeater and they seem to be the thing to use when you don't want a
table of results, but I'm not sure how to change the
<ItemTemplate> depending on the contents of the data.

For example if I wish a list of html links and headings in asp I would do
the following:-
'--------------------------------------------------

Response.Write "<TABLE BORDER=1 CELLSPACING=0 CELLPADDING=1>"
while not rs.eof
lngParent = CLng(rs("PARENT"))
lngEntity = CLng(rs("ENTITY"))
Response.Write "<TR>"
'##When the data in "PARENT" is 0 I want to display some text else I
want to output a blank cell then a link.
if lngParent = 0 then
Response.Write "<TH ALIGN=LEFT COLSPAN=2>" & trim(rs("PRODCODE")) &
"</TH>"
else
Response.Write "<TD width=20>&nbsp</TD><TD class=lnk1><A class='red'
HREF=""javascript:menu(" & lngEntity & ");"">" & trim(rs("PRODCODE")) &
"</A></TD>"

end if
Response.Write "</TR>"
rs.movenext
wend
Response.Write "</TABLE>"

'--------------------------------------------------

The javascript function "menu" would set a hidden field and submit the form.
Could someone give me an example of a repeater
using an "<asp:LinkButton .." or another method that would give me the same
result of the above code.
Could anyone suggest some good tutorials for aspx/dotNet - the ones I've
found so far are:-

http://docs.learnasp.com/quickstart/...uickstart.aspx
and
http://aspnet.4guysfromrolla.com/
cheers

Henry
Nov 18 '05 #1
3 1331
Hi Henry,

Here's a quick example:
<script runat=server>
myRepeater.DataSource = myDataSet("myTable")
DataBind
</script>
<asp:repeater runat=server id=myRepeater>
<itemtemplate>
<asp:placeholder visisble="<%#Container.DataItem.myTable.Parent = 0%>">
Parent is equal to Zero!
</asp:placeholder>
<asp:placeholder visisble="<%#Container.DataItem.myTable.Parent <> 0%>">
Parent is not equal to Zero, but equal to
<%#Container.DataItem.myTable.Parent%>
</asp:placeholder>
</itemtemplate>
</asp:repeater>

Hope that helps

-- Alex Papadimoulis
"Henry Nelson" <em***@minsterlogistics.com> wrote in message
news:c9**********@newsg2.svr.pol.co.uk...
Hi all

I'm very new to dotNet and just trying to get my head around the right way
to do the thing that I would normally do in asp.

In asp I would loop through a recordset and output all the html dynamically for the layout I want. I have seen some examples of
using a repeater and they seem to be the thing to use when you don't want a table of results, but I'm not sure how to change the
<ItemTemplate> depending on the contents of the data.

For example if I wish a list of html links and headings in asp I would do
the following:-
'--------------------------------------------------

Response.Write "<TABLE BORDER=1 CELLSPACING=0 CELLPADDING=1>"
while not rs.eof
lngParent = CLng(rs("PARENT"))
lngEntity = CLng(rs("ENTITY"))
Response.Write "<TR>"
'##When the data in "PARENT" is 0 I want to display some text else I
want to output a blank cell then a link.
if lngParent = 0 then
Response.Write "<TH ALIGN=LEFT COLSPAN=2>" & trim(rs("PRODCODE")) & "</TH>"
else
Response.Write "<TD width=20>&nbsp</TD><TD class=lnk1><A class='red'
HREF=""javascript:menu(" & lngEntity & ");"">" & trim(rs("PRODCODE")) &
"</A></TD>"

end if
Response.Write "</TR>"
rs.movenext
wend
Response.Write "</TABLE>"

'--------------------------------------------------

The javascript function "menu" would set a hidden field and submit the form. Could someone give me an example of a repeater
using an "<asp:LinkButton .." or another method that would give me the same result of the above code.
Could anyone suggest some good tutorials for aspx/dotNet - the ones I've
found so far are:-

http://docs.learnasp.com/quickstart/...uickstart.aspx
and
http://aspnet.4guysfromrolla.com/
cheers

Henry

Nov 18 '05 #2
Hi Alex

Thank you for your response. It looks like your sugestion is exaxtly what I
need if I can only
get it to work with my code/data.
The Visable=true/false is working but the html output I get is:-
---------------------------------------------------------------------------
<tr>
<td class=lnk1>
<asp:placeholder Visible="False">
Parent is equal to Zero!
</asp:placeholder>
<asp:placeholder Visible="True">
Parent is not equal to Zero
</asp:placeholder>
</td>
</tr>
---------------------------------------------------------------------------
Here is my sub I call to bind the repeater:-
---------------------------------------------------------------------------
Private Sub BindRepeater()
Dim strWebServer As String = Config.GetCS()
Dim conn As New SqlClient.SqlConnection(strWebServer)
Dim da As SqlClient.SqlDataAdapter
Dim dt As New DataTable
Dim strSql As String

strSql = "SELECT ENTITY, PARENT, PRODCODE FROM IOED WHERE RECTYPE=1"

conn.Open()
da = New SqlClient.SqlDataAdapter(strSql, conn)
da.Fill(dt)
conn.Close()

repMenu.DataSource = dt
repMenu.DataBind()

End Sub
---------------------------------------------------------------------------
Here is my new repeater:-
---------------------------------------------------------------------------
<asp:repeater id="repMenu" Runat="server" EnableViewState="false">
<ItemTemplate>
<tr>
<td>
<asp:placeholder Visible="<%#DataBinder.Eval(Container.DataItem,
"PARENT") = 0%>">
Parent is equal to Zero!
</asp:placeholder>
<asp:placeholder Visible="<%#DataBinder.Eval(Container.DataItem,
"PARENT") <> 0%>">
Parent is not equal to Zero
</asp:placeholder>
</td>
</tr>
</ItemTemplate>
</asp:repeater>
---------------------------------------------------------------------------

Any ideas what I'm doing wrong?
Nov 18 '05 #3
Got it working

Added runat="server" and changes the visable double quotes to singles.

Thanks again Alex, i've been searching for a solution for days.

cheers,

Henry

<asp:placeholder runat="server"
Visible='<%#Container.DataItem("PARENT") = 0%>'>
Parent is equal to Zero!
</asp:placeholder>
<asp:placeholder runat="server"
Visible='<%#Container.DataItem("PARENT") <> 0%>'>
Parent is not equal to Zero
</asp:placeholder>

"Henry Nelson" <em***@minsterlogistics.com> wrote in message
news:c9**********@news6.svr.pol.co.uk...
Hi Alex

Thank you for your response. It looks like your sugestion is exaxtly what I need if I can only
get it to work with my code/data.
The Visable=true/false is working but the html output I get is:-
-------------------------------------------------------------------------- - <tr>
<td class=lnk1>
<asp:placeholder Visible="False">
Parent is equal to Zero!
</asp:placeholder>
<asp:placeholder Visible="True">
Parent is not equal to Zero
</asp:placeholder>
</td>
</tr>
-------------------------------------------------------------------------- -

Here is my sub I call to bind the repeater:-
-------------------------------------------------------------------------- - Private Sub BindRepeater()
Dim strWebServer As String = Config.GetCS()
Dim conn As New SqlClient.SqlConnection(strWebServer)
Dim da As SqlClient.SqlDataAdapter
Dim dt As New DataTable
Dim strSql As String

strSql = "SELECT ENTITY, PARENT, PRODCODE FROM IOED WHERE RECTYPE=1"

conn.Open()
da = New SqlClient.SqlDataAdapter(strSql, conn)
da.Fill(dt)
conn.Close()

repMenu.DataSource = dt
repMenu.DataBind()

End Sub
-------------------------------------------------------------------------- -

Here is my new repeater:-
-------------------------------------------------------------------------- - <asp:repeater id="repMenu" Runat="server" EnableViewState="false">
<ItemTemplate>
<tr>
<td>
<asp:placeholder Visible="<%#DataBinder.Eval(Container.DataItem,
"PARENT") = 0%>">
Parent is equal to Zero!
</asp:placeholder>
<asp:placeholder Visible="<%#DataBinder.Eval(Container.DataItem,
"PARENT") <> 0%>">
Parent is not equal to Zero
</asp:placeholder>
</td>
</tr>
</ItemTemplate>
</asp:repeater>
-------------------------------------------------------------------------- -
Any ideas what I'm doing wrong?

Nov 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Svens | last post by:
Hey everyone! I'm a math student working on a short script involving logs. I have a function on my scientific calculator, and was wondering if there was a similar funtion in python. For example:...
3
by: jvax | last post by:
Hi all, I hope I'm posting in the right NG... I have a data text file I want to read from a c++ program. the data file goes like this: 90 # number of balls 33 42 13
1
by: Mike Malter | last post by:
I am just starting to work with reflection and I want to create a log that saves relevant information if a method call fails so I can call that method again later using reflection. I am...
14
by: z_learning_tester | last post by:
But I can't seem to find the answer. The question is how do you reverse the words in a string? Or how do you reverse the numbers listed in a string? The example is usually something like: Turn...
12
by: Blaze | last post by:
I am doing the first walk through on the Visual Studio .Net walkthrough book to learn a little about programming. I am having issues with the first tutorial not running correctly. It seems that...
5
by: optimistx | last post by:
As a beginner in javascript I had a question. I was reading FAQ and posts here. I became very unhappy: Obviously this group is mainly for wise, pedantic, unkind etc people, who already know...
10
by: Roman Zeilinger | last post by:
Hi I have a beginner question concerning fscanf. First I had a text file which just contained some hex numbers: 0C100012 0C100012 ....
4
by: a | last post by:
Dear all vb.net developer I want to know the time I need to master vb.net? I'm beginner
3
by: Ben Keshet | last post by:
I have a probably simple beginner's question - I have a script that I am currently able to print its output. instead, i want to write it into a file - I tried different versions of write() but...
2
by: roanhn | last post by:
Hello. I've to to write a master's thesis. Currently I deal with php, mysql, ajax. Fate decreed that I've to choose one of this subjects: 1.gdi+ library in .net technology 2.ado.net technology...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.