Beginner question

H

Henry Nelson

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/aspplus/doc/quickstart.aspx
and
http://aspnet.4guysfromrolla.com/


cheers

Henry
 
A

Alex Papadimoulis

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
 
H

Henry Nelson

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>
 
H

Henry Nelson

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>
 

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

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,060
Latest member
BuyKetozenseACV

Latest Threads

Top