listboxes.........

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • bill yeager

    #1

    listboxes.........

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

    <asp:TemplateCo lumn HeaderText="Cre w Chiefs">

    <ItemTemplate >

    <asp:listbox AutoPostBack="F alse"
    BackColor="#fff fff" id="lstCrewChie f" runat="server"
    Rows="1" DataSource="<%# DsCrewChief1 %>" Enabled="True"
    SelectionMode=" Single" DataTextField=" UserName"
    DataValueField= "UserName" />

    </asp:listbox>

    </ItemTemplate>

    </asp:TemplateCol umn>

    <asp:TemplateCo lumn HeaderText="EMT 's/Drivers">

    <ItemTemplate >

    <asp:listbox AutoPostBack="F alse"
    BackColor="#fff fff" id="lstEMTDrive r" runat="server"
    Rows="1" DataSource="<%# DsEMTDriver1 %>" Enabled="True"
    SelectionMode=" Single" DataTextField=" UserName"
    DataValueField= "UserName" />

    </asp:listbox>

    </ItemTemplate>

    </asp:TemplateCol umn>

    <asp:TemplateCo lumn HeaderText="Rid ers">

    <ItemTemplate >

    <asp:listbox AutoPostBack="F alse"
    BackColor="#fff fff" id="lstRider" runat="server" Rows="1"
    DataSource="<%# DsRider1 %>" Enabled="True"
    SelectionMode=" Multiple" DataTextField=" UserName"
    DataValueField= "UserName" />

    </asp:listbox>

    </ItemTemplate>

    </asp:TemplateCol umn>




    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_ItemD ataBound(ByVal sender As
    Object, ByVal e As
    System.Web.UI.W ebControls.Data GridItemEventAr gs) Handles
    DataGrid1.ItemD ataBound

    'Get the correct values for the listboxes
    If e.Item.ItemType = ListItemType.It em Then
    Dim lstCrewChiefTem p As ListBox
    Dim lstEMTsDriverTe mp As ListBox
    Dim lstRiderTemp As ListBox
    lstCrewChiefTem p = e.Item.FindCont rol
    ("lstCrewChief" )
    lstCrewChiefTem p.SelectedIndex =
    lstCrewChiefTem p.Items.IndexOf
    (lstCrewChiefTe mp.Items.FindBy Value(e.Item.Da taItem
    ("Username") ))
    lstEMTsDriverTe mp = e.Item.FindCont rol
    ("lstEMTDriver" )
    lstEMTsDriverTe mp.SelectedInde x =
    lstEMTsDriverTe mp.Items.IndexO f
    (lstEMTsDriverT emp.Items.FindB yValue(e.Item.D ataItem
    ("Username") ))
    lstRiderTemp = e.Item.FindCont rol("lstRider")
    lstRiderTemp.Se lectedIndex =
    lstRiderTemp.It ems.IndexOf(lst RiderTemp.Items .FindByValue
    (e.Item.DataIte m("Username") ))
    End If

    End Sub

    Thanks,

    Bill.
  • Prakash Ramdas

    #2
    listboxes...... ...

    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 lstCrewChiefTem p As ListBox
    lstCrewChiefTem p.Items.FindByV alue("123").Sel ected = 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.[color=blue]
    >-----Original Message-----
    >I have several template columns inside of a datagrid.
    >Inside of these template columns are databound listboxes:
    >
    ><asp:TemplateC olumn HeaderText="Cre w Chiefs">
    >
    > <ItemTemplate >
    >
    > <asp:listbox AutoPostBack="F alse"
    >BackColor="#ff ffff" id="lstCrewChie f" runat="server"
    >Rows="1" DataSource="<%# DsCrewChief1 %>" Enabled="True"
    >SelectionMode= "Single" DataTextField=" UserName"
    >DataValueField ="UserName" />
    >
    > </asp:listbox>
    >
    > </ItemTemplate>
    >
    > </asp:TemplateCol umn>
    >
    > <asp:TemplateCo lumn HeaderText="EMT 's/Drivers">
    >
    > <ItemTemplate >
    >
    > <asp:listbox AutoPostBack="F alse"
    >BackColor="#ff ffff" id="lstEMTDrive r" runat="server"
    >Rows="1" DataSource="<%# DsEMTDriver1 %>" Enabled="True"
    >SelectionMode= "Single" DataTextField=" UserName"
    >DataValueField ="UserName" />
    >
    > </asp:listbox>
    >
    > </ItemTemplate>
    >
    > </asp:TemplateCol umn>
    >
    > <asp:TemplateCo lumn HeaderText="Rid ers">
    >
    > <ItemTemplate >
    >
    > <asp:listbox AutoPostBack="F alse"
    >BackColor="#ff ffff" id="lstRider" runat="server" Rows="1"
    >DataSource="<% # DsRider1 %>" Enabled="True"
    >SelectionMode= "Multiple" DataTextField=" UserName"
    >DataValueField ="UserName" />
    >
    > </asp:listbox>
    >
    > </ItemTemplate>
    >
    > </asp:TemplateCol umn>
    >
    >
    >
    >
    >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[/color]
    I[color=blue]
    >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[/color]
    about[color=blue]
    >setting the values of the listboxes?
    >
    >Also, how do I set and retrieve values from a listbox[/color]
    that[color=blue]
    >can have multiple selections...
    >
    >Below is the code I have for the ItemDataBound
    >event......... ..
    >
    >
    > Private Sub DataGrid1_ItemD ataBound(ByVal sender As
    >Object, ByVal e As
    >System.Web.UI. WebControls.Dat aGridItemEventA rgs) Handles
    >DataGrid1.Item DataBound
    >
    > 'Get the correct values for the listboxes
    > If e.Item.ItemType = ListItemType.It em Then
    > Dim lstCrewChiefTem p As ListBox
    > Dim lstEMTsDriverTe mp As ListBox
    > Dim lstRiderTemp As ListBox
    > lstCrewChiefTem p = e.Item.FindCont rol
    >("lstCrewChief ")
    > lstCrewChiefTem p.SelectedIndex =
    >lstCrewChiefTe mp.Items.IndexO f
    >(lstCrewChiefT emp.Items.FindB yValue(e.Item.D ataItem
    >("Username") ))
    > lstEMTsDriverTe mp = e.Item.FindCont rol
    >("lstEMTDriver ")
    > lstEMTsDriverTe mp.SelectedInde x =
    >lstEMTsDriverT emp.Items.Index Of
    >(lstEMTsDriver Temp.Items.Find ByValue(e.Item. DataItem
    >("Username") ))
    > lstRiderTemp = e.Item.FindCont rol("lstRider")
    > lstRiderTemp.Se lectedIndex =
    >lstRiderTemp.I tems.IndexOf(ls tRiderTemp.Item s.FindByValue
    >(e.Item.DataIt em("Username")) )
    > End If
    >
    > End Sub
    >
    >Thanks,
    >
    >Bill.
    >.
    >[/color]

    Comment

    • bill yeager

      #3
      listboxes...... ...

      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........
      [color=blue]
      >-----Original Message-----
      >Answer to Qn1.
      >
      >ItemDataBoun d is the method that is called just after[/color]
      the[color=blue]
      >Data binding is over. This is the place where you add[/color]
      your[color=blue]
      >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[/color]
      for[color=blue]
      >ItemTypes.
      >
      >Dim lstCrewChiefTem p As ListBox
      >lstCrewChiefTe mp.Items.FindBy Value("123").Se lected = 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.[color=green]
      >>-----Original Message-----
      >>I have several template columns inside of a datagrid.
      >>Inside of these template columns are databound[/color][/color]
      listboxes:[color=blue][color=green]
      >>
      >><asp:Template Column HeaderText="Cre w Chiefs">
      >>
      >> <ItemTemplate >
      >>
      >> <asp:listbox AutoPostBack="F alse"
      >>BackColor="#f fffff" id="lstCrewChie f" runat="server"
      >>Rows="1" DataSource="<%# DsCrewChief1 %>"[/color][/color]
      Enabled="True"[color=blue][color=green]
      >>SelectionMode ="Single" DataTextField=" UserName"
      >>DataValueFiel d="UserName" />
      >>
      >> </asp:listbox>
      >>
      >> </ItemTemplate>
      >>
      >> </asp:TemplateCol umn>
      >>
      >> <asp:TemplateCo lumn HeaderText="EMT 's/Drivers">
      >>
      >> <ItemTemplate >
      >>
      >> <asp:listbox AutoPostBack="F alse"
      >>BackColor="#f fffff" id="lstEMTDrive r" runat="server"
      >>Rows="1" DataSource="<%# DsEMTDriver1 %>"[/color][/color]
      Enabled="True"[color=blue][color=green]
      >>SelectionMode ="Single" DataTextField=" UserName"
      >>DataValueFiel d="UserName" />
      >>
      >> </asp:listbox>
      >>
      >> </ItemTemplate>
      >>
      >> </asp:TemplateCol umn>
      >>
      >> <asp:TemplateCo lumn HeaderText="Rid ers">
      >>
      >> <ItemTemplate >
      >>
      >> <asp:listbox AutoPostBack="F alse"
      >>BackColor="#f fffff" id="lstRider" runat="server"[/color][/color]
      Rows="1"[color=blue][color=green]
      >>DataSource="< %# DsRider1 %>" Enabled="True"
      >>SelectionMode ="Multiple" DataTextField=" UserName"
      >>DataValueFiel d="UserName" />
      >>
      >> </asp:listbox>
      >>
      >> </ItemTemplate>
      >>
      >> </asp:TemplateCol umn>
      >>
      >>
      >>
      >>
      >>I would like to do 2 things with these listboxes: One,[/color][/color]
      is[color=blue][color=green]
      >>to set the selected value in the listbox to the values[/color][/color]
      I[color=blue][color=green]
      >>retrieve in the database. The second, is to set the
      >>selected values in the listboxes to values before I[/color][/color]
      write[color=blue][color=green]
      >>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[/color][/color]
      (which[color=blue]
      >I[color=green]
      >>think it is)? If so, is there an event I need to use to
      >>SET the values in the listboxes to the values I[/color][/color]
      retrieved[color=blue][color=green]
      >>from the database? If there is no event, how do I go[/color]
      >about[color=green]
      >>setting the values of the listboxes?
      >>
      >>Also, how do I set and retrieve values from a listbox[/color]
      >that[color=green]
      >>can have multiple selections...
      >>
      >>Below is the code I have for the ItemDataBound
      >>event........ ...
      >>
      >>
      >> Private Sub DataGrid1_ItemD ataBound(ByVal sender As
      >>Object, ByVal e As
      >>System.Web.UI .WebControls.Da taGridItemEvent Args)[/color][/color]
      Handles[color=blue][color=green]
      >>DataGrid1.Ite mDataBound
      >>
      >> 'Get the correct values for the listboxes
      >> If e.Item.ItemType = ListItemType.It em Then
      >> Dim lstCrewChiefTem p As ListBox
      >> Dim lstEMTsDriverTe mp As ListBox
      >> Dim lstRiderTemp As ListBox
      >> lstCrewChiefTem p = e.Item.FindCont rol
      >>("lstCrewChie f")
      >> lstCrewChiefTem p.SelectedIndex =
      >>lstCrewChiefT emp.Items.Index Of
      >>(lstCrewChief Temp.Items.Find ByValue(e.Item. DataItem
      >>("Username")) )
      >> lstEMTsDriverTe mp = e.Item.FindCont rol
      >>("lstEMTDrive r")
      >> lstEMTsDriverTe mp.SelectedInde x =
      >>lstEMTsDriver Temp.Items.Inde xOf
      >>(lstEMTsDrive rTemp.Items.Fin dByValue(e.Item .DataItem
      >>("Username")) )
      >> lstRiderTemp = e.Item.FindCont rol[/color][/color]
      ("lstRider")[color=blue][color=green]
      >> lstRiderTemp.Se lectedIndex =
      >>lstRiderTemp. Items.IndexOf[/color][/color]
      (lstRiderTemp.I tems.FindByValu e[color=blue][color=green]
      >>(e.Item.DataI tem("Username") ))
      >> End If
      >>
      >> End Sub
      >>
      >>Thanks,
      >>
      >>Bill.
      >>.
      >>[/color]
      >.
      >[/color]

      Comment

      • bill yeager

        #4
        listboxes...... ...

        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........
        [color=blue]
        >-----Original Message-----
        >Answer to Qn1.
        >
        >ItemDataBoun d is the method that is called just after[/color]
        the[color=blue]
        >Data binding is over. This is the place where you add[/color]
        your[color=blue]
        >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[/color]
        for[color=blue]
        >ItemTypes.
        >
        >Dim lstCrewChiefTem p As ListBox
        >lstCrewChiefTe mp.Items.FindBy Value("123").Se lected = 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.[color=green]
        >>-----Original Message-----
        >>I have several template columns inside of a datagrid.
        >>Inside of these template columns are databound[/color][/color]
        listboxes:[color=blue][color=green]
        >>
        >><asp:Template Column HeaderText="Cre w Chiefs">
        >>
        >> <ItemTemplate >
        >>
        >> <asp:listbox AutoPostBack="F alse"
        >>BackColor="#f fffff" id="lstCrewChie f" runat="server"
        >>Rows="1" DataSource="<%# DsCrewChief1 %>"[/color][/color]
        Enabled="True"[color=blue][color=green]
        >>SelectionMode ="Single" DataTextField=" UserName"
        >>DataValueFiel d="UserName" />
        >>
        >> </asp:listbox>
        >>
        >> </ItemTemplate>
        >>
        >> </asp:TemplateCol umn>
        >>
        >> <asp:TemplateCo lumn HeaderText="EMT 's/Drivers">
        >>
        >> <ItemTemplate >
        >>
        >> <asp:listbox AutoPostBack="F alse"
        >>BackColor="#f fffff" id="lstEMTDrive r" runat="server"
        >>Rows="1" DataSource="<%# DsEMTDriver1 %>"[/color][/color]
        Enabled="True"[color=blue][color=green]
        >>SelectionMode ="Single" DataTextField=" UserName"
        >>DataValueFiel d="UserName" />
        >>
        >> </asp:listbox>
        >>
        >> </ItemTemplate>
        >>
        >> </asp:TemplateCol umn>
        >>
        >> <asp:TemplateCo lumn HeaderText="Rid ers">
        >>
        >> <ItemTemplate >
        >>
        >> <asp:listbox AutoPostBack="F alse"
        >>BackColor="#f fffff" id="lstRider" runat="server"[/color][/color]
        Rows="1"[color=blue][color=green]
        >>DataSource="< %# DsRider1 %>" Enabled="True"
        >>SelectionMode ="Multiple" DataTextField=" UserName"
        >>DataValueFiel d="UserName" />
        >>
        >> </asp:listbox>
        >>
        >> </ItemTemplate>
        >>
        >> </asp:TemplateCol umn>
        >>
        >>
        >>
        >>
        >>I would like to do 2 things with these listboxes: One,[/color][/color]
        is[color=blue][color=green]
        >>to set the selected value in the listbox to the values[/color][/color]
        I[color=blue][color=green]
        >>retrieve in the database. The second, is to set the
        >>selected values in the listboxes to values before I[/color][/color]
        write[color=blue][color=green]
        >>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[/color][/color]
        (which[color=blue]
        >I[color=green]
        >>think it is)? If so, is there an event I need to use to
        >>SET the values in the listboxes to the values I[/color][/color]
        retrieved[color=blue][color=green]
        >>from the database? If there is no event, how do I go[/color]
        >about[color=green]
        >>setting the values of the listboxes?
        >>
        >>Also, how do I set and retrieve values from a listbox[/color]
        >that[color=green]
        >>can have multiple selections...
        >>
        >>Below is the code I have for the ItemDataBound
        >>event........ ...
        >>
        >>
        >> Private Sub DataGrid1_ItemD ataBound(ByVal sender As
        >>Object, ByVal e As
        >>System.Web.UI .WebControls.Da taGridItemEvent Args)[/color][/color]
        Handles[color=blue][color=green]
        >>DataGrid1.Ite mDataBound
        >>
        >> 'Get the correct values for the listboxes
        >> If e.Item.ItemType = ListItemType.It em Then
        >> Dim lstCrewChiefTem p As ListBox
        >> Dim lstEMTsDriverTe mp As ListBox
        >> Dim lstRiderTemp As ListBox
        >> lstCrewChiefTem p = e.Item.FindCont rol
        >>("lstCrewChie f")
        >> lstCrewChiefTem p.SelectedIndex =
        >>lstCrewChiefT emp.Items.Index Of
        >>(lstCrewChief Temp.Items.Find ByValue(e.Item. DataItem
        >>("Username")) )
        >> lstEMTsDriverTe mp = e.Item.FindCont rol
        >>("lstEMTDrive r")
        >> lstEMTsDriverTe mp.SelectedInde x =
        >>lstEMTsDriver Temp.Items.Inde xOf
        >>(lstEMTsDrive rTemp.Items.Fin dByValue(e.Item .DataItem
        >>("Username")) )
        >> lstRiderTemp = e.Item.FindCont rol[/color][/color]
        ("lstRider")[color=blue][color=green]
        >> lstRiderTemp.Se lectedIndex =
        >>lstRiderTemp. Items.IndexOf[/color][/color]
        (lstRiderTemp.I tems.FindByValu e[color=blue][color=green]
        >>(e.Item.DataI tem("Username") ))
        >> End If
        >>
        >> End Sub
        >>
        >>Thanks,
        >>
        >>Bill.
        >>.
        >>[/color]
        >.
        >[/color]

        Comment

        • Prakash

          #5
          listboxes...... ...

          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("Inse rtMode") = True Then
          CType(e.Item.Ce lls(6).FindCont rol("CompanyNam e"),
          DropDownList).I tems.Insert(0, New ListItem("Selec t one", -
          99))
          Else
          ID = CType(e.Item.Ce lls(5).FindCont rol("CompanyID" ),
          LiteralControl) .Text
          CType(e.Item.Ce lls(6).FindCont rol("CompanyNam e"),
          DropDownList).I tems.FindByValu e(ID).Selected = True
          End If

          Hope this helps.
          Prakash R.[color=blue]
          >-----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........
          >[color=green]
          >>-----Original Message-----
          >>Answer to Qn1.
          >>
          >>ItemDataBou nd is the method that is called just after[/color]
          >the[color=green]
          >>Data binding is over. This is the place where you add[/color]
          >your[color=green]
          >>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[/color]
          >for[color=green]
          >>ItemTypes.
          >>
          >>Dim lstCrewChiefTem p As ListBox
          >>lstCrewChiefT emp.Items.FindB yValue("123").S elected = 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.[color=darkred]
          >>>-----Original Message-----
          >>>I have several template columns inside of a datagrid.
          >>>Inside of these template columns are databound[/color][/color]
          >listboxes:[color=green][color=darkred]
          >>>
          >>><asp:Templat eColumn HeaderText="Cre w Chiefs">
          >>>
          >>> <ItemTemplate >
          >>>
          >>> <asp:listbox AutoPostBack="F alse"
          >>>BackColor="# ffffff" id="lstCrewChie f" runat="server"
          >>>Rows="1" DataSource="<%# DsCrewChief1 %>"[/color][/color]
          >Enabled="Tru e"[color=green][color=darkred]
          >>>SelectionMod e="Single" DataTextField=" UserName"
          >>>DataValueFie ld="UserName" />
          >>>
          >>> </asp:listbox>
          >>>
          >>> </ItemTemplate>
          >>>
          >>> </asp:TemplateCol umn>
          >>>
          >>> <asp:TemplateCo lumn HeaderText="EMT 's/Drivers">
          >>>
          >>> <ItemTemplate >
          >>>
          >>> <asp:listbox AutoPostBack="F alse"
          >>>BackColor="# ffffff" id="lstEMTDrive r" runat="server"
          >>>Rows="1" DataSource="<%# DsEMTDriver1 %>"[/color][/color]
          >Enabled="Tru e"[color=green][color=darkred]
          >>>SelectionMod e="Single" DataTextField=" UserName"
          >>>DataValueFie ld="UserName" />
          >>>
          >>> </asp:listbox>
          >>>
          >>> </ItemTemplate>
          >>>
          >>> </asp:TemplateCol umn>
          >>>
          >>> <asp:TemplateCo lumn HeaderText="Rid ers">
          >>>
          >>> <ItemTemplate >
          >>>
          >>> <asp:listbox AutoPostBack="F alse"
          >>>BackColor="# ffffff" id="lstRider" runat="server"[/color][/color]
          >Rows="1"[color=green][color=darkred]
          >>>DataSource=" <%# DsRider1 %>" Enabled="True"
          >>>SelectionMod e="Multiple" DataTextField=" UserName"
          >>>DataValueFie ld="UserName" />
          >>>
          >>> </asp:listbox>
          >>>
          >>> </ItemTemplate>
          >>>
          >>> </asp:TemplateCol umn>
          >>>
          >>>
          >>>
          >>>
          >>>I would like to do 2 things with these listboxes: One,[/color][/color]
          >is[color=green][color=darkred]
          >>>to set the selected value in the listbox to the values[/color][/color]
          >I[color=green][color=darkred]
          >>>retrieve in the database. The second, is to set the
          >>>selected values in the listboxes to values before I[/color][/color]
          >write[color=green][color=darkred]
          >>>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[/color][/color]
          >(which[color=green]
          >>I[color=darkred]
          >>>think it is)? If so, is there an event I need to use to
          >>>SET the values in the listboxes to the values I[/color][/color]
          >retrieved[color=green][color=darkred]
          >>>from the database? If there is no event, how do I go[/color]
          >>about[color=darkred]
          >>>setting the values of the listboxes?
          >>>
          >>>Also, how do I set and retrieve values from a listbox[/color]
          >>that[color=darkred]
          >>>can have multiple selections...
          >>>
          >>>Below is the code I have for the ItemDataBound
          >>>event....... ....
          >>>
          >>>
          >>> Private Sub DataGrid1_ItemD ataBound(ByVal sender As
          >>>Object, ByVal e As
          >>>System.Web.U I.WebControls.D ataGridItemEven tArgs)[/color][/color]
          >Handles[color=green][color=darkred]
          >>>DataGrid1.It emDataBound
          >>>
          >>> 'Get the correct values for the listboxes
          >>> If e.Item.ItemType = ListItemType.It em Then
          >>> Dim lstCrewChiefTem p As ListBox
          >>> Dim lstEMTsDriverTe mp As ListBox
          >>> Dim lstRiderTemp As ListBox
          >>> lstCrewChiefTem p = e.Item.FindCont rol
          >>>("lstCrewChi ef")
          >>> lstCrewChiefTem p.SelectedIndex =
          >>>lstCrewChief Temp.Items.Inde xOf
          >>>(lstCrewChie fTemp.Items.Fin dByValue(e.Item .DataItem
          >>>("Username") ))
          >>> lstEMTsDriverTe mp = e.Item.FindCont rol
          >>>("lstEMTDriv er")
          >>> lstEMTsDriverTe mp.SelectedInde x =
          >>>lstEMTsDrive rTemp.Items.Ind exOf
          >>>(lstEMTsDriv erTemp.Items.Fi ndByValue(e.Ite m.DataItem
          >>>("Username") ))
          >>> lstRiderTemp = e.Item.FindCont rol[/color][/color]
          >("lstRider")[color=green][color=darkred]
          >>> lstRiderTemp.Se lectedIndex =
          >>>lstRiderTemp .Items.IndexOf[/color][/color]
          >(lstRiderTemp. Items.FindByVal ue[color=green][color=darkred]
          >>>(e.Item.Data Item("Username" )))
          >>> End If
          >>>
          >>> End Sub
          >>>
          >>>Thanks,
          >>>
          >>>Bill.
          >>>.
          >>>[/color]
          >>.
          >>[/color]
          >.
          >[/color]

          Comment

          Working...