Repeater OnItemCommand

R

RN1

I have a Repeater control with 2 columns - the data under the 1st
column are links whereas those in the 2nd column are just text.

<script runat="server">
Sub Page_Load(.......)
'populating the Repeater & binding the data to it
End Sub

Sub Item_Command(ByVal obj As Object, ByVal ea As
RepeaterCommandEventArgs)
'If (Page.IsPostBack) Then
' rptrUsers.DataBind()
'End If
End Sub

Sub Item_DataBound(ByVal obj As Object, ByVal ea As
RepeaterItemEventArgs)
Response.Write("Data Bound<hr>")
If (Page.IsPostBack) Then
rptrUsers.DataBind()
End If
End Sub

Sub Item_Created(ByVal obj As Object, ByVal ea As
RepeaterItemEventArgs)
Response.Write("Item Created<br>")
End Sub
</script>

<form runat="server">
<asp:Repeater ID="rptrUsers" OnItemCommand="Item_Command"
OnItemCreated="Item_Created" OnItemDataBound="Item_DataBound"
runat="server">
....................
....................
....................
</asp:Repeater>
</form>

Assuming that the Repeater gets populated with 5 rows, when I run the
above code for the first time, OnItemCreated & OnItemDataBound fires 7
times - once for the header, 5 times for the 5 rows & once for the
footer.

Note the code in the sub named Item_Command which is commented. If I
uncomment the 3 lines & then click a link in the Repeater, the
Repeater no longer gets displayed.

Why so?

Thanks,

Ron
 
N

Nathan Sokalski

The reason is because before performing the databinding, you must populate a
DataTable (or whatever you are using as your data source) and assign it to
the Repeater's DataSource property. simply calling the DataBind() method
will pretty much just be binding the Repeater to a DataSource with a value
of Nothing. Hopefully this helps.
 

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

Similar Threads

IsPostBack 4
OnItemCommand & OnItemDataBound 2
DataBind In ItemDataBound Event 1
ViewState? 1
DataBind 1
Repeater Item? 1
repeater 0
OnItemCommand DataList 0

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top