Getting Dataitem from a Repeateritem?

  • Thread starter Thread starter champ.supernova
  • Start date Start date
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?
 
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
 
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.
 
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 -
 
Back
Top