Go Back   DeveloperBarn Forums > Programming & Scripting > .Net Development

Sponsored Links

Discuss "accessing items in datasource" in the .Net Development forum.

.Net Development - Learn about the Microsoft.Net framework and how to create powerful web-based (ASP.net) and client-based (Windows Forms) applications utilizing various languages such as C#, VB.Net, J# and others.


Reply « Previous Thread | Next Thread »  
 
LinkBack Thread Tools Display Modes
  #1  
Old July 9th, 2008, 04:24 AM
Shem's Avatar
Barn Enthusiast

 
Join Date: Mar 2008
Posts: 261
Thanks: 30
Thanked 5 Times in 5 Posts
Rep Power: 1
Shem is on a distinguished road
Default accessing items in datasource

Hi

i'm populating a Repeater like so:
Code:
Dim ProjectsList As New ProjectsList
ProjectsList = ProjectsManager.GetList(orderby)

rpProjectList.DataSource = ProjectsList
rpProjectList.DataBind()
what i want to do is access the items and perform some operations on them
and then bind it to my Repeater.

I was thinking that I would nead to do a 'For each item in ProjectsList'
but i couldn't get it right?

am i going about this all wrong
Shem
Reply With Quote
Sponsored Links
  #2  
Old July 9th, 2008, 04:32 AM
richyrich's Avatar
Moderator


 
Join Date: Mar 2008
Location: Somewhere only we know...
Posts: 395
Thanks: 26
Thanked 32 Times in 32 Posts
Blog Entries: 1
Rep Power: 1
richyrich will become famous soon enough

Awards Showcase
Classic ASP JavaScript 
Total Awards: 2

Default

Not wrong. What you need to do is bind the data to the repeater and then have OnItemDataBound in your repeater control.

.aspx
Code:
<asp:repeater id="repeater1" runat="server" OnItemDataBound="repeater1_OnItemDataBound">
.aspx.vb
Code:
Protected Sub repeater1_OnItemDataBound(ByVal s As Object, ByVal e As RepeaterItemEventArgs)
 
If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
 
  Dim textbox1 As textbox = e.item.FindControl("textbox1")
  Dim Project As ProjectBOL = e.Item.DataItem
 
  'Do whatever you want with your values
   if Project.editedby = "shem" then 
       textbox1.Text = "Some Idiot"
   else
       textbox1.Text = "A Brilliant Employee"
   End If
 
End If
 
End Sub
Might need to make some small edits to this code before you use it. Just waiting for my laptop to reboot and typed that off the top of my head.

That's the basic principle though. Use OnItemDataBound

Last edited by richyrich; July 9th, 2008 at 04:54 AM.
Reply With Quote
The Following User Says Thank You to richyrich For This Useful Post:
Shem (July 9th, 2008)
  #3  
Old July 9th, 2008, 04:43 AM
micky's Avatar
Barn Frequenter

 
Join Date: Jul 2008
Location: India
Posts: 101
Thanks: 10
Thanked 3 Times in 2 Posts
Rep Power: 1
micky is on a distinguished road
Default

lol RR
i love that if loop

Comments on this post
Shem agrees: thanks
Reply With Quote
  #4  
Old July 9th, 2008, 04:44 AM
Shem's Avatar
Barn Enthusiast

 
Join Date: Mar 2008
Posts: 261
Thanks: 30
Thanked 5 Times in 5 Posts
Rep Power: 1
Shem is on a distinguished road
Default

explain to me what's going on here?
Code:
If e.Item.ItemType = ItemType.Item Or e.Item.ItemType = ItemType.AlternatingItem Then
Is that some .Net jargon or am i supposed to replace it with my own conditions?

Shem
Reply With Quote
  #5  
Old July 9th, 2008, 04:49 AM
Shem's Avatar
Barn Enthusiast

 
Join Date: Mar 2008
Posts: 261
Thanks: 30
Thanked 5 Times in 5 Posts
Rep Power: 1
Shem is on a distinguished road
Default

not bad for writing of the top off your head RR, I see it is .Net jargon..
changed it slightly to:
Code:
If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
Shem
Reply With Quote
  #6  
Old July 9th, 2008, 04:51 AM
richyrich's Avatar
Moderator


 
Join Date: Mar 2008
Location: Somewhere only we know...
Posts: 395
Thanks: 26
Thanked 32 Times in 32 Posts
Blog Entries: 1
Rep Power: 1
richyrich will become famous soon enough

Awards Showcase
Classic ASP JavaScript 
Total Awards: 2

Default

Quote:
Originally Posted by Shem View Post
not bad for writing of the top off your head RR, I see it is .Net jargon..
changed it slightly to:
Code:
If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
Shem
Yeah, what you said...

The reason I can never remember them is because VWD autocompletes code for you, so I never have to type it...

<edit>Changed my code above</edit>

Last edited by richyrich; July 9th, 2008 at 04:55 AM.
Reply With Quote
Reply

  DeveloperBarn Forums > Programming & Scripting > .Net Development

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
populate datasource control from DDL Shem .Net Development 22 June 30th, 2008 08:14 AM
Accessing a Public Property in a web service richyrich .Net Development 0 May 23rd, 2008 08:42 AM
Accessing controls in the Footer of a datalist richyrich .Net Development 6 May 12th, 2008 12:19 PM
Accessing skmmenu control in Master Page richyrich .Net Development 13 March 18th, 2008 11:45 AM


All times are GMT -4. The time now is 04:24 PM.



Content Relevant URLs by vBSEO 3.2.0