some databinding techniqes neede using in listview -

Discussion in 'ASP .Net' started by mesut, Aug 11, 2008.

  1. mesut

    mesut Guest

    Hi colleagues,

    I hope someone have experience with these databinding techniques in
    aspx... and can explain me the reason?

    I've got a listview and I would like to fix these #3 problems just to
    learn how to do it...

    can someone help me what is wrong in my code? I won't get squeezed
    line or whatever.. so the syntax looks correct.

    ( 1 )
    this works
    <td><%# ((DateTime)Eval("DeliveredDate")).ToShortDateString()%></td>

    I would like to do - put date in dd-MMM-yyy
    <td><%# ((DateTime)Eval("DeliveredDate")).ToShortDateString("dd-MMM-
    yyyy")%></td>

    result: CS1501: No overload for method 'ToShortDateString' takes '1'
    arguments.
    why? how can I get dd-MMM-yyy?????


    ( 2 )
    this works
    <td><%# GetCityDescription("Amsterdam")%></td>

    I would like to pass in by Eval("flexible city here")
    <td><%# GetCityDescription(Eval("City"))%></td>

    result: GetCityDescription(string)' has some invalid arguments

    NOTE: GetcityDescription is a protected function in code behind...

    why can't I use Eval?????? how can I fix this?


    ( 3 )
    this works <td><%# Eval("OrderDate").ToString()%></td>
    but I would like to get in dd-MMM-yyyy
    <td><%# Eval("OrderDate").ToString("dd-MMM-yyyy")%></td>

    I get this error: CS1501: No overload for method 'ToString' takes '1'
    arguments


    Can someone explain me why I get these errors? I mean why can't I do
    these? I would like to understand the reason??


    the last thing maybe in the dates what happens if the fields contains
    null or are blanks (no date in the table) will that dump? How can I
    avoid this than too :)

    thanks
    mesut
    mesut, Aug 11, 2008
    #1
    1. Advertising

  2. mesut

    Lloyd Sheen Guest

    Comments inline:

    mesut wrote:
    > Hi colleagues,
    >
    > I hope someone have experience with these databinding techniques in
    > aspx... and can explain me the reason?
    >
    > I've got a listview and I would like to fix these #3 problems just to
    > learn how to do it...
    >
    > can someone help me what is wrong in my code? I won't get squeezed
    > line or whatever.. so the syntax looks correct.
    >
    > ( 1 )
    > this works
    > <td><%# ((DateTime)Eval("DeliveredDate")).ToShortDateString()%></td>
    >
    > I would like to do - put date in dd-MMM-yyy
    > <td><%# ((DateTime)Eval("DeliveredDate")).ToShortDateString("dd-MMM-
    > yyyy")%></td>
    >
    > result: CS1501: No overload for method 'ToShortDateString' takes '1'
    > arguments.
    > why? how can I get dd-MMM-yyy?????



    The function ToShortDateString will return a predefined formatted
    string. You want to use toString(format String) to return the format
    you want. The applicable format strings for date are found at

    http://msdn.microsoft.com/en-us/library/az4se3k1.aspx


    >
    >
    > ( 2 )
    > this works
    > <td><%# GetCityDescription("Amsterdam")%></td>
    >
    > I would like to pass in by Eval("flexible city here")
    > <td><%# GetCityDescription(Eval("City"))%></td>
    >
    > result: GetCityDescription(string)' has some invalid arguments
    >
    > NOTE: GetcityDescription is a protected function in code behind...
    >
    > why can't I use Eval?????? how can I fix this?
    >


    Not close to VS at present but you want to look for page methods as the
    cure for this problem.

    >
    > ( 3 )
    > this works <td><%# Eval("OrderDate").ToString()%></td>
    > but I would like to get in dd-MMM-yyyy
    > <td><%# Eval("OrderDate").ToString("dd-MMM-yyyy")%></td>
    >
    > I get this error: CS1501: No overload for method 'ToString' takes '1'
    > arguments


    You need to cast "OrderDate" to a date to be able to use the format
    string (see above for applicable string values"


    >
    >
    > Can someone explain me why I get these errors? I mean why can't I do
    > these? I would like to understand the reason??
    >
    >
    > the last thing maybe in the dates what happens if the fields contains
    > null or are blanks (no date in the table) will that dump? How can I
    > avoid this than too :)
    >
    > thanks
    > mesut



    LS
    Lloyd Sheen, Aug 11, 2008
    #2
    1. Advertising

  3. mesut

    Stan Guest

    On 11 Aug, 16:17, mesut <> wrote:
    > Hi colleagues,
    >
    > I hope someone have experience with these databinding techniques in
    > aspx... and can explain me the reason?
    >
    > I've got a listview and I would like to fix these #3 problems just to
    > learn how to do it...
    >
    > can someone help me what is wrong in my code? I won't get squeezed
    > line or whatever.. so the syntax looks correct.
    >
    > ( 1 )
    > this works
    >  <td><%# ((DateTime)Eval("DeliveredDate")).ToShortDateString()%></td>
    >
    > I would like to do  - put date in dd-MMM-yyy
    >  <td><%# ((DateTime)Eval("DeliveredDate")).ToShortDateString("dd-MMM-
    > yyyy")%></td>
    >
    > result: CS1501: No overload for method 'ToShortDateString' takes '1'
    > arguments.
    > why? how can I get dd-MMM-yyy?????
    >
    > ( 2 )
    > this works
    > <td><%# GetCityDescription("Amsterdam")%></td>
    >
    > I would like to pass in by Eval("flexible city here")
    > <td><%# GetCityDescription(Eval("City"))%></td>
    >
    > result: GetCityDescription(string)' has some invalid arguments
    >
    > NOTE: GetcityDescription is a protected function in code behind...
    >
    > why can't I use Eval??????  how can I fix this?
    >
    > ( 3 )
    > this works <td><%# Eval("OrderDate").ToString()%></td>
    > but I would like to get in dd-MMM-yyyy
    > <td><%# Eval("OrderDate").ToString("dd-MMM-yyyy")%></td>
    >
    > I get this error: CS1501: No overload for method 'ToString' takes '1'
    > arguments
    >
    > Can someone explain me why I get these errors? I mean why can't I do
    > these? I would like to understand the reason??
    >
    > the last thing maybe in the dates what happens if the fields contains
    > null or are blanks (no date in the table) will that dump? How can I
    > avoid this than too :)
    >
    > thanks
    > mesut


    In addition to what Lloyd has said the key point here is that the
    Eval() function returns an object which has to be cast to the required
    type. Normally the DataBinder does this for you but if you have more
    complex expressions requiring intermediate evaluation steps then you
    have to embed type casting or conversion methods in the <%# ... %>
    expression.

    In your case (2) your could try
    GetCityDescription(Eval(<cityName>).ToString())
    Stan, Aug 11, 2008
    #3
  4. mesut

    mesut Guest

    thank you very much LS and Stan.

    thanks to the information you sent I solved the problem.

    many thanks again...


    mesut
    mesut, Aug 12, 2008
    #4
    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. =?Utf-8?B?UmFqYQ==?=
    Replies:
    0
    Views:
    802
    =?Utf-8?B?UmFqYQ==?=
    Sep 16, 2004
  2. delgados129
    Replies:
    2
    Views:
    784
    delgados129
    Apr 25, 2005
  3. Sheldon

    makefile knowledge neede

    Sheldon, Mar 2, 2008, in forum: C Programming
    Replies:
    2
    Views:
    599
    Keith Thompson
    Mar 2, 2008
  4. Roshawn
    Replies:
    0
    Views:
    251
    Roshawn
    Mar 21, 2008
  5. .
    Replies:
    0
    Views:
    704
Loading...

Share This Page