Problem of Cast/Datagrid - Code Behind Bis (felix)

F

Fabrice

Hello,

First, thanks to felix for his answer.

But :-( , I'm feeling newbie :! I' don't understand all the situation.
The trouble :

Always in the road whith my Datagrid and my ItemTemplate with a Control
HyperLink.
I would like to fix many properties of this Control Hyperlink in the Code
Behind. I'm using the Datagrid OnItemCreated Event.

So, I can establish a lot of properties of the Control like that :

--- In the file .aspx, in the Datagrid Control :

OnItemCreated="myDatagrid_ItemCreated"


---- In the code behind file (.aspx .vb)


Sub myDatagrid_ItemCreated(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DataGridItemEventArgs)

If e.Item.ItemType = ListItemType.Item Then

CType(e.Item.FindControl("lnkControl"),
HyperLink).Text="myText"

End If

-->> It's OK.

But I have always the problem with the property NavigateUrl of thisControl
Hyperlink (or CommandArgument property for an another control like
ImageButton).

Question : How can I access to the value of a cell in the DataGrid in the
OnItemCreated Event. I'm referring to thedata bound in the datagrid.

Example of try :
CType(e.Item.FindControl("lnkFamBreDetail"),
HyperLink).NavigateUrl="mapage.aspx?" & Value (of my column bound)
OR CType(e.Item.FindControl("lnkControl"),
Hyperlink).CommandArgument = DataBound


The DataGrid is bound with a DataView (Based on a dataset).

I ' ve try this Felix's Solution (thanks)) but it does not work or i 'm very
stupid :-(

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("lnkControl"),
Hyperlink).CommandArgument = CType(drvTemp.Row.Item("Column"),
System.String) --> Here I have an error. My Column is not recognized.

End if

how referred to the databound?

I'm lost in the deep datagrid ....
Thanks for you help

fabrice
(sorry for my poor english)
 
G

Guest

Hi Fabrice,

I would suggest you to use ItemDataBound event rather than ItemCreated
event, because in the first event you can access underlying data source.

The following code snippet shows how to get data and reference of columns:

If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType =
ListItemType.AlternatingItem Then
Dim drv As DataRowView = CType(e.Item.DataItem, DataRowView)
Dim link As HyperLink =
Ctype(e.Item.FindControl(“lnkFamBreDetailâ€),HyperLink)
Link.NavigateUrl="mapage.aspx?queryID=" + drv(“Column_nameâ€).ToString
End If


HTH

Elton Wang
 
F

Fabrice

Hi.

It works fine with OnItemDataBound. Thanks a lot.
Have a nice week end.

fabrice.
 

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,969
Messages
2,570,161
Members
46,708
Latest member
SherleneF1

Latest Threads

Top