casting problem in Datagrid - Option Strict in use

F

fabrice

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.
 
G

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
 

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

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top