Tuesday, October 15, 2013

ItemDataBound event for repeater control

Here i am giving one simple example for ItemDataBound event. In this block of code i am finding one label and assigning a value.

/* Code block started */
  Dim listOfparticipant As New Generic.List(Of registerParticipant)
  Dim participant As New registerParticipant 
  listOfparticipant.Add(participant)

  rptVerifyParticipant.DataSource = listOfparticipant
  rptVerifyParticipant.DataBind()

  Protected Sub rptVerifyParticipant_ItemDataBound(ByVal sender As Object, ByVal e As    System.Web.UI.WebControls.RepeaterItemEventArgs) Handles rptVerifyParticipant.ItemDataBound

 If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then

 Dim _tbl As registerParticipant = CType(e.Item.DataItem, registerParticipant)
            Dim VerifyNric As Label = CType(e.Item.FindControl("VerifyNric"), Label)
            VerifyNric.Text = Microsoft.SharePoint.Utilities.SPHttpUtility.HtmlEncode(Convert.ToString(_tbl.NRIC))

End If
 End Sub

/* Code block End */

In this block i have created on list of "registerParticipan" class, and after that adding one item to this list , after that i am assigning to repeater data source.

Now after that will write itemDatabound event .
In itemdatabound event we are typcasting item.dataitem to registerParticipant class .

Thanks,