Datalist and container.dataitem problem

C

Chumley the Walrus

I have a datalist, and I need to display the appropriate weekday
contigent upon the date that exists in my 'showdate' record (which is
a datetime datatype):

<%
if weekday(Container.dataItem("showdate")) = 2 then
response.write "monday"
end if %>

.....gives me a "Container is not declared" error

?????
chum
 
C

Chumley the Walrus

Konrad Rotuski said:
you have to use DataBinding syntax ( <%#%> )

no, that doesnt work in this context. Error will state : Statement end
expected. I Need to find a way to use Container.dataItem("showdate")
in a way to manipulate the data and do something with it besides
display it in a datalist.
 
K

Konrad Rotuski

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

DataBinding expression has to return value, not response.write

just return as string what response.write was writing, it should work that
way

for Container.DataItem as DataRowView :

Protected Function ReturnString(drv as DataRowView) As String
if weekday(drv("showdate")) = 2 then
return "monday"
else
return String.Empty
end if
End Function

and in aspx :

<%#ReturnString(Container.DataItem)%>

it worked for me always

HTH
 
C

Chumley the Walrus

Konrad Rotuski said:
<%#DataBinder.Eval(Container.DataItem, "showdate")%>

DataBinding expression has to return value, not response.write

just return as string what response.write was writing, it should work that
way

for Container.DataItem as DataRowView :
Protected Function ReturnString(drv as DataRowView) As String
if weekday(drv("showdate")) = 2 then
return "monday"
else
return String.Empty
end if
End Function

How do you declare "drv" with this function?
I'm getting an error : Specified cast is not valid
 
K

Konrad Rotuski

Chumley the Walrus said:
"Konrad Rotuski" <konrad@_SPAM_KILLER_eracent.com> wrote in message


How do you declare "drv" with this function?
you can put here byval, i was writing this by hand, so vs.net didn't put it
there :)
I'm getting an error : Specified cast is not valid
thats because Container.DataItem is not DataRowView, if you are binding
datatable then you will get DataRowView, what do you bind to datalist ?

look here for more Container.DataItem info :
http://weblogs.asp.net/rajbk/archive/2004/07/20/188868.aspx
 
C

Chumley the Walrus

(chumley:) I'm getting an error : Specified cast is not valid
(konrad:)thats because Container.DataItem is not DataRowView, if you are binding
datatable then you will get DataRowView, what do you bind to datalist ?

<script language="VB" runat="server">
Sub Page_Load(Src As Object, E As EventArgs)
Dim strConn as string
="SERVER=xx.xx.xx.x;UID=xxxxxx;PWD=xxxxx;DATABASE=xxxxxxx;"
Dim strSQL as string ="select * from tblProline"
Dim Conn as New sqlConnection(strConn)
Dim Cmd as New sqlCommand(strSQL,Conn)
Conn.Open()
thedata.DataSource =
Cmd.ExecuteReader(system.data.CommandBehavior.CloseConnection)
thedata.DataBind()
End Sub
 

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,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top