.NET Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgramming.NET Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old August 8th, 2003, 03:49 PM
wsyeager wsyeager is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: Weston, FL
Posts: 32 wsyeager User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Send a message via Yahoo to wsyeager
Red face listboxes...........

I have several template columns inside of a datagrid. Inside of these template columns are databound listboxes:

<asp:TemplateColumn HeaderText="Crew Chiefs">
<ItemTemplate>
<asp:listbox AutoPostBack="False" BackColor="#ffffff" id="lstCrewChief" runat="server" Rows="1" DataSource="<%# DsCrewChief1 %>" Enabled="True" SelectionMode="Single" DataTextField="UserName" DataValueField="UserName" />
</asp:listbox>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="EMT's/Drivers">
<ItemTemplate>
<asp:listbox AutoPostBack="False" BackColor="#ffffff" id="lstEMTDriver" runat="server" Rows="1" DataSource="<%# DsEMTDriver1 %>" Enabled="True" SelectionMode="Single" DataTextField="UserName" DataValueField="UserName" />
</asp:listbox>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Riders">
<ItemTemplate>
<asp:listbox AutoPostBack="False" BackColor="#ffffff" id="lstRider" runat="server" Rows="1" DataSource="<%# DsRider1 %>" Enabled="True" SelectionMode="Multiple" DataTextField="UserName" DataValueField="UserName" />
</asp:listbox>
</ItemTemplate>
</asp:TemplateColumn>




I would like to do 2 things with these listboxes: One, is to set the selected value in the listbox to the values I retrieve in the database. The second, is to set the selected values in the listboxes to values before I write the data to the database.

I'm confused about the ITEMDatabound event of the datagrid. Is this event used to get the values of the listboxes BEFORE I write the data to the database (which I think it is)? If so, is there an event I need to use to SET the values in the listboxes to the values I retrieved from the database? If there is no event, how do I go about setting the values of the listboxes?

Also, how do I set and retrieve values from a listbox that can have multiple selections...

Below is the code I have for the ItemDataBound event...........


Private Sub DataGrid1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles DataGrid1.ItemDataBound

'Get the correct values for the listboxes
If e.Item.ItemType = ListItemType.Item Then
Dim lstCrewChiefTemp As ListBox
Dim lstEMTsDriverTemp As ListBox
Dim lstRiderTemp As ListBox
lstCrewChiefTemp = e.Item.FindControl("lstCrewChief")
lstCrewChiefTemp.SelectedIndex = lstCrewChiefTemp.Items.IndexOf(lstCrewChiefTemp.It ems.FindByValue(e.Item.DataItem("Username")))
lstEMTsDriverTemp = e.Item.FindControl("lstEMTDriver")
lstEMTsDriverTemp.SelectedIndex = lstEMTsDriverTemp.Items.IndexOf(lstEMTsDriverTemp. Items.FindByValue(e.Item.DataItem("Username")))
lstRiderTemp = e.Item.FindControl("lstRider")
lstRiderTemp.SelectedIndex = lstRiderTemp.Items.IndexOf(lstRiderTemp.Items.Find ByValue(e.Item.DataItem("Username")))
End If

End Sub
__________________
Thanks,

Bill Yeager BCIP, MCP
BrainBench Certified Internet Professional
Microsoft Certified Professional

Reply With Quote
Reply

Viewing: ASP Free ForumsProgramming.NET Development > listboxes...........


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT