Getting Dataitem from a Repeateritem?

C

champ.supernova

I have a repeater containing dropdownlists. This subroutine is called
when the selected index on one of these dropdownlists is changed...


Public Sub cmbProductType_SelectedIndexChanged(ByVal sender As Object,
ByVal e As System.EventArgs)

Dim cmbProductType As DropDownList = CType(sender,
DropDownList)
Dim objRepeaterItem As RepeaterItem = cmbProductType.Parent

Label1.Text =
Convert.ToString(DataBinder.Eval(objRepeaterItem.DataItem,
"intProductID"))

End Sub


....all I'm trying to do is to simply retrieve the dataitem
"intProductID" from whichever 'row' of the repeater the dropdownlist
belongs to, but have been banging my head against a brick wall up to
now. I thought the syntax I had above would do it, but I just get a
null returned.

The equivalent syntax for an event called relating to the repeater is
'e.Item.DataItem("intProductID")', with e being the
RepeaterItemEventArgs.

I can't find any clear examples anywhere on the Internet either. Has
anyone managed to do anything like this?
 
E

Eliyahu Goldin

DataItem is available only in ItemDataBound event. That is the only time
when the repeater gets connected with its datasource. You may want to get
intProductID values in a hidden html input control. You will need to include
the control into your itemtemplate.

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

champ.supernova

I should just clarify, when I say 'dropdownlists' I mean multiple
instances of the same one - i.e. in the ItemTemplate there is actually
just the one.
 
C

champ.supernova

Ah, that makes sense. Thanks Eliyahu, will give that a go.


DataItem is available only in ItemDataBound event. That is the only time
when the repeater gets connected with its datasource. You may want to get
intProductID values in a hidden html input control. You will need to include
the control into your itemtemplate.

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




I have a repeater containing dropdownlists. This subroutine is called
when the selected index on one of these dropdownlists is changed...
Public Sub cmbProductType_SelectedIndexChanged(ByVal sender As Object,
ByVal e As System.EventArgs)
Dim cmbProductType As DropDownList = CType(sender,
DropDownList)
Dim objRepeaterItem As RepeaterItem = cmbProductType.Parent
Label1.Text =
Convert.ToString(DataBinder.Eval(objRepeaterItem.DataItem,
"intProductID"))
...all I'm trying to do is to simply retrieve the dataitem
"intProductID" from whichever 'row' of the repeater the dropdownlist
belongs to, but have been banging my head against a brick wall up to
now. I thought the syntax I had above would do it, but I just get a
null returned.
The equivalent syntax for an event called relating to the repeater is
'e.Item.DataItem("intProductID")', with e being the
RepeaterItemEventArgs.
I can't find any clear examples anywhere on the Internet either. Has
anyone managed to do anything like this?- Hide quoted text -

- Show quoted text -
 

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,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top