newbie question about asp tags

C

Citizen10Bears

I'm trying to use asp to create an sql string, and then use that sql
string with as accessdatasource asp tag.
This doesn't work.

<%
dim sql
sql="select * from bytable"
%>

<asp:AccessDataSource ID="dsOptions" runat="server"
DataFile="~/data/db.mdb"
SelectCommand="<%=sql%>">
</asp:AccessDataSource>



Am I being a complete idiot?
I think my problem lies with not quite understanding when exaclty old
asp tags are calculated (<%%>) compared with new asp.net tags (<asp:>)

Any advice? (To an oldskool asp expert!)

Cheers
 
J

Jon Paal

try

<%
dim sql
sql="select * from bytable"
dsOptions.SelectCommand = sql
%>

<asp:AccessDataSource ID="dsOptions" runat="server"
DataFile="~/data/db.mdb"
</asp:AccessDataSource>
 
C

Citizen10Bears

lovely solution, I'll try it in a mo,

but where is my understanding wrong initially?

cheers
 
C

Citizen10Bears

while I have your assistance Jon, do you mind if I ask another
question?

take this line...

<%# eval("field")%>

what does the # indicate?

also, with reference to the earlier example I now have something like
this...

<%dsOptions.SelectCommand = "select * from mytable where id="%><%#
Eval("pollid")%>

which fails. The <%# Eval("id")%> on its own works fine but I can't
concatenate the value to my selectcommand!?

I have also tried

<%dsOptions.SelectCommand = "select * from mytable where id=" & #
Eval("pollid")%>
but I get complaints at the #, and complaints if I remove it.

any clues?

many thanks for your quick answering tonight!
 
J

Jon Paal

you're mixing up a lot of delimiters

Data binding expressions in ASP.NET are the small snippets of code you see between <%# and %> characters in an ASPX file. We
normally see these expressions in a Repeater's ItemTemplate declarations, and in a DataGrid's TemplateColumn markup. Also, Data
binding expressions often contain a call to the DataBinder.Eval method.

you can't mix these inside and outside of the <asp: tags

I recommend you pick up a manual on ASP.net to learn the syntax.
 
C

Citizen10Bears

thanks,

yes, I am inside a repeater.
I'm trying to get a nested repeater to work based on the outer
repeater. I perhaps should have explained this earlier on.
Code follows...
the outer repeater (repeater1) gets rows from tblpolls
the inner repeater (repeater2) should use pollid to get related rows
from tblpolloptions

is this not a sensible way to go?
searching for any help on the accessdatasource, particularly with
nested repeaters that uses accessdatasource is pretty fruitless.

Thanks

<asp:AccessDataSource ID="dsPolls" runat="server"
DataFile="~/data/db.mdb"
SelectCommand="select * from tblpolls order by pollid desc">
</asp:AccessDataSource>

<asp:AccessDataSource ID="dsOptions" runat="server"
DataFile="~/data/db.mdb">
</asp:AccessDataSource>

<asp:Repeater ID="Repeater1" runat="server"
DataSourceID="dsPolls">
<ItemTemplate>
<asp:Label runat="server" ID="Label1" Text='<%#
Eval("polltitle") %>' />

<%
dsOptions.SelectCommand = "select * from tblpolloptions
where pollid=" & DataBinder.Eval(Me.dsPolls, "pollid")
dsOptions.Select(New
System.Web.UI.DataSourceSelectArguments)
dsOptions.DataBind()
%>

<asp:Repeater ID="Repeater2" runat="server"
DataSourceID="dsOptions">
<ItemTemplate>
<asp:Label runat="server" ID="Label6" Text='<%#
Eval("optiontext") %>' />
</ItemTemplate>
</asp:Repeater>
</asp:Repeater>
 
J

Jon Paal

I don't know what the error message is but if it is not working as desired, there may be a problem in the timing of obtaining
information.

This can usually be addressed by placing code in the correct area of the page life cycle.

(isn't ASP.net fun... :)
 
C

Citizen10Bears

vb to vb.net - a real joy, fantastic.

asp to asp.net - so far no benefits that I can see over regular asp.

maybe I need to change my view and forget everything I know about
regular asp. maybe it's time to move to java!

:)

Tim
 
J

Jon Paal

asp.net and asp are totally different.

It's much more difficult to produce anything in ASP.net because you must first learn all about asp.net OOP
3 month learning curve. No such thing as just in time learning in this environment.

And, if you don't use it all the time, whatever you had will be quickly lost.

And if not lost, it will be revised by MS because ASP.net versions are radically different


:)
 

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,774
Messages
2,569,596
Members
45,143
Latest member
DewittMill
Top