Datalist and container.dataitem problem

Discussion in 'ASP .Net Web Controls' started by Chumley the Walrus, Aug 13, 2004.

  1. 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
    Chumley the Walrus, Aug 13, 2004
    #1
    1. Advertising

  2. you have to use DataBinding syntax ( <%#%> )
    Konrad Rotuski, Aug 13, 2004
    #2
    1. Advertising

  3. "Konrad Rotuski" <konrad@_SPAM_KILLER_eracent.com> wrote in message news:<>...
    > 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.
    Chumley the Walrus, Aug 13, 2004
    #3
  4. <%#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

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

    news:<>...
    > > 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.
    Konrad Rotuski, Aug 16, 2004
    #4
  5. "Konrad Rotuski" <konrad@_SPAM_KILLER_eracent.com> wrote in message news:<#>...
    > <%#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
    Chumley the Walrus, Aug 17, 2004
    #5
  6. "Chumley the Walrus" <> wrote in message
    news:...
    > "Konrad Rotuski" <konrad@_SPAM_KILLER_eracent.com> wrote in message

    news:<#>...
    > > <%#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?

    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
    Konrad Rotuski, Aug 17, 2004
    #6
  7. > >(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
    Chumley the Walrus, Aug 17, 2004
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Lauchlan M
    Replies:
    1
    Views:
    7,236
    Lauchlan M
    Oct 15, 2003
  2. Vishal

    Container.DataItem and Button

    Vishal, Dec 14, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    2,003
    Isaias Formacio-Serna
    Dec 14, 2004
  3. .Net Sports
    Replies:
    5
    Views:
    456
    .Net Sports
    Jun 15, 2007
  4. OrlandoRocks

    Container.DataItem in ASCX problem

    OrlandoRocks, Jul 15, 2003, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    188
    OrlandoRocks
    Jul 15, 2003
  5. Joe Rattz
    Replies:
    2
    Views:
    598
    Robert Koritnik
    Sep 10, 2004
Loading...

Share This Page