casting problem in Datagrid - Option Strict in use

Discussion in 'ASP .Net' started by fabrice, Aug 30, 2005.

  1. fabrice

    fabrice Guest

    Hello


    I have a little problem with casting in a Datagrid Control. I'm using Option
    Strict in my web application.

    In a Template Column, I put in an ImageButton Control with a Command
    Argument using Container.DataItem.
    Différent expressions as
    System.Convert.ToString(Container.DataItem("Column"))) bring an Error :

    BC30574: Option Strict ...Late Binding


    I would like to use Container.DataItem instead of DataBinder.Eval for
    optimisation. But I don't managed to find the right Cast.
    I try these solutions with no success:

    CommandArgument='<%# String.Format("{0:c}", (CType(Container,
    DataGridItem).DataItem("Column"))) %> '

    or

    CommandArgument='<%#CType(Container, DataGridItem).DataItem,
    "IDEBRE").ToString()%> '



    This solution works :

    CommandArgument='<%# Convert.ToString(DataBinder.Eval(CType(Container,
    DataGridItem).DataItem, "idebre"))) %>'

    ....but use DataBinder.Eval argument.



    I' don't understand the Casting problem (Late Binding) with
    Container.DataGridItem.


    Thanks for you help.

    Fabrice.
     
    fabrice, Aug 30, 2005
    #1
    1. Advertisements

  2. fabrice

    Guest Guest

    Try adding the following to the ItemCreated event in the VB file


    If e.Item.ItemType = ListItemType.Item Then

    Dim drvTemp As System.Data.DataRowView
    drvTemp = CType(e.Item.DataItem, System.Data.DataRowView)
    CType(e.Item.FindControl("imgButtonID"),
    LinkButton).CommandArgument = CType(drvTemp.Row.Item("Column"), System.String)
    End If

    If e.Item.ItemType = ListItemType.AlternatingItem Then
    Dim drvTemp As System.Data.DataRowView
    drvTemp = CType(e.Item.DataItem, System.Data.DataRowView)
    CType(e.Item.FindControl("imgButtonID"),
    LinkButton).CommandArgument = CType(drvTemp.Row.Item("Column"), System.String)
    End If


    Cheers

    Felix
     
    Guest, Aug 30, 2005
    #2
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.