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.Items.FindByValue(e.Item.DataIte m
("Username")))
lstEMTsDriverTemp = e.Item.FindControl
("lstEMTDriver")
lstEMTsDriverTemp.SelectedIndex =
lstEMTsDriverTemp.Items.IndexOf
(lstEMTsDriverTemp.Items.FindByValue(e.Item.DataIt em
("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. 4 1894
Answer to Qn1.
ItemDataBound is the method that is called just after the
Data binding is over. This is the place where you add your
code to choose what is selected in the list box.
You can do it this way.
Put this code in ItemDataBound with your regular check for
ItemTypes.
Dim lstCrewChiefTemp As ListBox
lstCrewChiefTemp.Items.FindByValue("123").Selected = True
Answer for Qn2.
You can access the multiple items selected in ListBox as
follows.
dim item as ListItem
For Each item in List1.Items
if item.Selected = True Then
'code to process the selected items.
End if
Next
I guess this is what you are looking for. If NOT please
reply back.
With Regards
Prakash R. -----Original Message----- 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
Ithink 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
aboutsetting the values of the listboxes?
Also, how do I set and retrieve values from a listbox
thatcan 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.Items.FindByValue(e.Item.DataIt em ("Username"))) lstEMTsDriverTemp = e.Item.FindControl ("lstEMTDriver") lstEMTsDriverTemp.SelectedIndex = lstEMTsDriverTemp.Items.IndexOf (lstEMTsDriverTemp.Items.FindByValue(e.Item.DataI tem ("Username"))) lstRiderTemp = e.Item.FindControl("lstRider") lstRiderTemp.SelectedIndex = lstRiderTemp.Items.IndexOf(lstRiderTemp.Items.Fin dByValue (e.Item.DataItem("Username"))) End If
End Sub
Thanks,
Bill. .
Prakash, is there an event I can use to set the values of
the respective listboxes once I get to the page.
At first, I load the listboxes (if not already in cache),
then, I want to set the selected values in the listboxes
to what they are in the database (via another query from
a previous user update that the user had selected prior).
If there is no event I can use, I was planning on looping
thru the columns in the datagrid and setting the values
of the listboxes that way........ -----Original Message----- Answer to Qn1.
ItemDataBound is the method that is called just after
theData binding is over. This is the place where you add
yourcode to choose what is selected in the list box.
You can do it this way.
Put this code in ItemDataBound with your regular check
forItemTypes.
Dim lstCrewChiefTemp As ListBox lstCrewChiefTemp.Items.FindByValue("123").Selecte d = True
Answer for Qn2.
You can access the multiple items selected in ListBox as follows.
dim item as ListItem For Each item in List1.Items if item.Selected = True Then 'code to process the selected items. End if
Next
I guess this is what you are looking for. If NOT please reply back.
With Regards Prakash R.-----Original Message----- 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,
isto set the selected value in the listbox to the values
Iretrieve in the database. The second, is to set the selected values in the listboxes to values before I
writethe 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
(whichIthink it is)? If so, is there an event I need to use to SET the values in the listboxes to the values I
retrievedfrom the database? If there is no event, how do I go aboutsetting the values of the listboxes?
Also, how do I set and retrieve values from a listbox thatcan 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.DataGridItemEventArg s)
HandlesDataGrid1.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.Items.FindByValue(e.Item.DataI tem ("Username"))) lstEMTsDriverTemp = e.Item.FindControl ("lstEMTDriver") lstEMTsDriverTemp.SelectedIndex = lstEMTsDriverTemp.Items.IndexOf (lstEMTsDriverTemp.Items.FindByValue(e.Item.Data Item ("Username"))) lstRiderTemp = e.Item.FindControl
("lstRider") lstRiderTemp.SelectedIndex = lstRiderTemp.Items.IndexOf
(lstRiderTemp.Items.FindByValue(e.Item.DataItem("Username"))) End If
End Sub
Thanks,
Bill. . .
Prakash, is there an event I can use to set the values of
the respective listboxes once I get to the page.
At first, I load the listboxes (if not already in cache),
then, I want to set the selected values in the listboxes
to what they are in the database (via another query from
a previous user update that the user had selected prior).
If there is no event I can use, I was planning on looping
thru the columns in the datagrid and setting the values
of the listboxes that way........ -----Original Message----- Answer to Qn1.
ItemDataBound is the method that is called just after
theData binding is over. This is the place where you add
yourcode to choose what is selected in the list box.
You can do it this way.
Put this code in ItemDataBound with your regular check
forItemTypes.
Dim lstCrewChiefTemp As ListBox lstCrewChiefTemp.Items.FindByValue("123").Selecte d = True
Answer for Qn2.
You can access the multiple items selected in ListBox as follows.
dim item as ListItem For Each item in List1.Items if item.Selected = True Then 'code to process the selected items. End if
Next
I guess this is what you are looking for. If NOT please reply back.
With Regards Prakash R.-----Original Message----- 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,
isto set the selected value in the listbox to the values
Iretrieve in the database. The second, is to set the selected values in the listboxes to values before I
writethe 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
(whichIthink it is)? If so, is there an event I need to use to SET the values in the listboxes to the values I
retrievedfrom the database? If there is no event, how do I go aboutsetting the values of the listboxes?
Also, how do I set and retrieve values from a listbox thatcan 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.DataGridItemEventArg s)
HandlesDataGrid1.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.Items.FindByValue(e.Item.DataI tem ("Username"))) lstEMTsDriverTemp = e.Item.FindControl ("lstEMTDriver") lstEMTsDriverTemp.SelectedIndex = lstEMTsDriverTemp.Items.IndexOf (lstEMTsDriverTemp.Items.FindByValue(e.Item.Data Item ("Username"))) lstRiderTemp = e.Item.FindControl
("lstRider") lstRiderTemp.SelectedIndex = lstRiderTemp.Items.IndexOf
(lstRiderTemp.Items.FindByValue(e.Item.DataItem("Username"))) End If
End Sub
Thanks,
Bill. . .
Bill,
I would still use ItemDataBound to set the listbox
selection.
Here is an example of how I acheived in my own problem.
The datagrid is databound. I have a column with the value
of the listbox to be set with the selection. So, to set
the listbox I pick the value from the other column, which
is bound just before this event. In case where no
selection is available for the row, a default string is
inserted and selected in the listbox.
If ViewState("InsertMode") = True Then
CType(e.Item.Cells(6).FindControl("CompanyName"),
DropDownList).Items.Insert(0, New ListItem("Select one", -
99))
Else
ID = CType(e.Item.Cells(5).FindControl("CompanyID"),
LiteralControl).Text
CType(e.Item.Cells(6).FindControl("CompanyName"),
DropDownList).Items.FindByValue(ID).Selected = True
End If
Hope this helps.
Prakash R. -----Original Message----- Prakash, is there an event I can use to set the values of the respective listboxes once I get to the page.
At first, I load the listboxes (if not already in cache), then, I want to set the selected values in the listboxes to what they are in the database (via another query from a previous user update that the user had selected prior).
If there is no event I can use, I was planning on looping thru the columns in the datagrid and setting the values of the listboxes that way........
-----Original Message----- Answer to Qn1.
ItemDataBound is the method that is called just after theData binding is over. This is the place where you add yourcode to choose what is selected in the list box.
You can do it this way.
Put this code in ItemDataBound with your regular check forItemTypes.
Dim lstCrewChiefTemp As ListBox lstCrewChiefTemp.Items.FindByValue("123").Select ed = True
Answer for Qn2.
You can access the multiple items selected in ListBox as follows.
dim item as ListItem For Each item in List1.Items if item.Selected = True Then 'code to process the selected items. End if
Next
I guess this is what you are looking for. If NOT please reply back.
With Regards Prakash R.-----Original Message----- I have several template columns inside of a datagrid. Inside of these template columns are databoundlistboxes: <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,isto set the selected value in the listbox to the valuesIretrieve in the database. The second, is to set the selected values in the listboxes to values before Iwritethe 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(whichIthink it is)? If so, is there an event I need to use to SET the values in the listboxes to the values I retrievedfrom the database? If there is no event, how do I go aboutsetting the values of the listboxes?
Also, how do I set and retrieve values from a listbox thatcan 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 )HandlesDataGrid1.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.Items.FindByValue(e.Item.Data Item ("Username"))) lstEMTsDriverTemp = e.Item.FindControl ("lstEMTDriver") lstEMTsDriverTemp.SelectedIndex = lstEMTsDriverTemp.Items.IndexOf (lstEMTsDriverTemp.Items.FindByValue(e.Item.Dat aItem ("Username"))) lstRiderTemp = e.Item.FindControl("lstRider") lstRiderTemp.SelectedIndex = lstRiderTemp.Items.IndexOf(lstRiderTemp.Items.FindByValue(e.Item.DataItem("Username"))) End If
End Sub
Thanks,
Bill. . . . This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Jeffrey Barish |
last post by:
I have an application that produces two listboxes. I would like to be
able to select one of the items in the first listbox and one of the
items in the second listbox. However, when I make my...
|
by: softengine |
last post by:
Can and how do you alter a data view to include a look up field from another
data table? The data table of the dataview only has the key, the value I need
is in another data table.
Can and how...
|
by: Simon Templar |
last post by:
I need the following functionality: With 2 listboxes populated from a
database with the SAME data, I need any of the listboxes to stop displaying
the option when selected at the other listbox. Eg:...
|
by: Susan Bricker |
last post by:
Hi. I have two questions ...
(1) I want to use a Listbox to enable the user to select 1 or many items
from the list. However, I'm having trouble figuring out how to find out
t which items have...
|
by: Terry D |
last post by:
I'm having an issue with an ASP.NET page (VS.NET 2003, VB.NET, Oracle
back end). The page uses the standard VS.NET grid to display the
records from a particular table. The user can edit certain...
|
by: Ryan Ternier |
last post by:
I have two listboxes, and allow users to move items between them via the
following function:
function SwitchList(fbox, tbox){
var arrFbox = new Array();
var arrTbox = new Array();
var...
|
by: Luis Esteban Valencia |
last post by:
have a problem and I'm not sure how to handle/fix it.
I have three listboxes on my page. The first listbox has a list of software
products. When you select an item in the Products listbox, then...
|
by: salad |
last post by:
This is a tip on how to speed up listboxes DRAMATICALLY. Persons that
would benefit are those that are constantly updating the rowsource of a
listbox/combobox in order to filter and sort the data...
|
by: amidala |
last post by:
Hello, everyone, i've recently started using C# and i'm rather new to this language. I'm trying to make a small project now that is combining the basic knowledge of programming (according to me :) )....
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM).
In this month's session, the creator of the excellent VBE...
|
by: DolphinDB |
last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation.
Take...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: Aftab Ahmad |
last post by:
Hello Experts!
I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
| |