DataList ItemTemplates and their access

polynaux

Member
Joined
Apr 3, 2007
Messages
11
Programming Experience
Beginner
My DataList ItemTemplate:


--------------------
UserId:[UserIdLabel]
Add
--------------------

If I click on add the method (code behind) fires.
The only thing I need is to get the UserId to use
it in my function.

Protected Sub LinkButton_Click(ByVal sender As Object, ByVal e As System.EventArgs)


TextBox1.Text = DirectCast(DataListSearchResults.Items(DataListSearchResults.SelectedIndex).FindControl("UserId"), Label).Text

End Sub

But my approach of direct casting and finding the control has an error:
Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index

Do you guys have a suggestion how to fix this ?


Many thanks,

Polynaux
 
also tried

I also tried it with:

TextBox1.Text = TryCast(DataListSearchResults.SelectedItem.FindControl("UserId"), Label).Text

TextBox1.Text = DataListSearchResults.SelectedItem.FindControl("UserIdLabel").ToString

But nothign seems so work.
 
Back
Top