How to get a ID into a tablerow of a datagrid

R

rwerkhoven

Not sure if the subject covers the story to well, but I hope someone
can help me with this little problem. I have a div that turns switches
to visible and invisible when going over a row in a datagrid. I shows
some information about the hightlighted product. For every row there
is a div generated with it's own id.

Now the problem is, when you want to put an onmouseout event in a
table row, you have to do it something like this:


Private Sub viewGrid_ItemDataBound(ByVal sender As Object, ByVal e
As System.Web.UI.WebControls.DataGridItemEventArgs) Handles
viewGrid.ItemDataBound
If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType =
ListItemType.AlternatingItem Then
e.Item.Attributes.Add("onmouseout", "hide(this, ds" &
prodId & ")")
End If
End Sub

But I can't seem to get the ID filled with the id I retrieve from
tablerow where I fill datagrid with.

Does anyone have an idea of how to do this?

Thanks,

Ricky
 
R

rwerkhoven

If you need the id that the row will have on client side, you can get it as
e.Item.ClientID. Or you mean something else?

Thanks for your quick reply, but indeed, I mean something else. What I
need is the prodId that I select from a table.

"SELECT producten.id as <b>prodId</b>, producten.omschrijving1 as
prodOmschr1, producten.omschrijving2 as prodOmschr2, prodSoort.naam as
prodSoort, producten.jaar as prodJaar, producten.foto as prodFoto,
prodStreken.naam as prodStreek, prodLanden.naam as prodLand,
producten.prijs as prodPrijs " & _
" FROM producten, prodSoort, prodStreken, prodLanden " & _
" WHERE producten.soort = prodSoort.id and producten.streek =
prodStreken.id and producten.land = prodLanden.id"
Dim objConnection As New
OdbcConnection(ConfigurationManager.AppSettings("connString"))
Dim objAdapter As New OdbcDataAdapter(strMySQL, objConnection)
Dim objDataSet As New DataSet()

With this query I fill the datagrid. On each row of the datagrid I
have a mouseover atribute. This mouseover should be accompanied with
the orderId.

Hope I'm clearer now. :)

Thnx
 
E

Eliyahu Goldin

e.Item.DataItem gives you a reference on the item in the datasource that
gets bound to the current grid row. You need to typecast it to the type of
your datasource and from there you can get to the fields. prodId will be in
the first field.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
 
R

rwerkhoven

e.Item.DataItem gives you a reference on the item in the datasource that
gets bound to the current grid row. You need to typecast it to the type of
your datasource and from there you can get to the fields. prodId will be in
the first field.

I'm sorry, I don't think I understand you completely. What do you mean
with "typecast it to the type of your datasource"?

Thanks.
 
E

Eliyahu Goldin

If you know that you databind the grid to a datatable, you know that the
type of DataItem will be DataRowView.

Look up the MSDN on DataItem. It has an example.
http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.datagriditem.dataitem(vs.71).aspx

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net


e.Item.DataItem gives you a reference on the item in the datasource that
gets bound to the current grid row. You need to typecast it to the type
of
your datasource and from there you can get to the fields. prodId will be
in
the first field.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP
[ASP.NET]http://msmvps.com/blogs/egoldinhttp://usableasp.net

I'm sorry, I don't think I understand you completely. What do you mean
with "typecast it to the type of your datasource"?

Thanks.
 

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,995
Messages
2,570,236
Members
46,825
Latest member
VernonQuy6

Latest Threads

Top