Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx_beginners thread: DropDownList SelectedIndex (PLEASE HELP)


Message #1 by "Miguel Simoes" <mjsimoes@m...> on Thu, 6 Jun 2002 00:22:39 +0100
This is a multi-part message in MIME format.

------=_NextPart_000_0020_01C20CF0.44423830
Content-Type: text/plain;
	charset="us-ascii"
Content-Transfer-Encoding: 7bit

Help me on the code (VB) for a DropDownlist selectedIndex.
 
What I Have : 
 - (Inventory web Page---Sql database) - I have to change the owner and
the local were Hardware is placed in my institution . 
 - In a datagrid I have a Template column (with Itemtemplate and
EditItemTemplate)
 - In EditItemtemplate I have two DropDownlists so that I can change the
User and the local where Hardawre is .
- DropdownLists are populated with Dataviews :
           
  SUB PopulateMyDropDownList()
      Dim DataAdapter as SqlDataAdapter
      Dim Ds as New Dataset()
      Dim SelectCmd as String="Select num, STR(Num) + ' - ' + Nom as
Name from Table_inventory ORDER By Nom"
      DataAdapter = New SqlDataAdapter(SelectCmd, myconnection)
     dataAdapter.Fill(DS, "TempInfo")
      DropDownDataView = DS.Tables("TempInfo").defaultView
END SUB
      
It Works perfectly and I get my DropDownList Populated from the
database.
 
 
How do I get my DropDownList SelectedIndex?
 
WHAT I Tried doesn't work:
.........
    SelectedIndex= '<%# getNameIndex(Container.DataItem("Nom"))%>
........
 
 
Public Function getNameIndex(Name as String) As Integer
     Dim cRow as DataRow
     Dim Index as Int64=0
     for each cRow in dropdownDataview
       If Crow("Nom") = Name then
           Index=Crow("Num")
           exit for
       end If
     Next
 return Index
 
End Function
 
 
ERROR Returned : "Specified cast is not valid"
 
 
Thanks in advance,
 
Miguel Simoes
LISBOA - PORTUGAL


Message #2 by jdonahue@f... on Thu, 6 Jun 2002 17:45:45
If I understood all of this correctly, some of the info you can get is:
SelectedValue = EmpPerm.SelectedItem.Value
SelectedText = EmpPerm.SelectedItem.Text
SelectedIndex = <YourList>.Items.IndexOf(<YourList>.Items.FindByText
(SelectedText))
SelectedIndex = <YourList>.Items.IndexOf(<YourList>.Items.FindByValue
(SelectedValue))
-Jim

Session("TempEmpPermName") = EmpPerm.SelectedItem.Text

> This is a multi-part message in MIME format.

------=_NextPart_000_0020_01C20CF0.44423830
Content-Type: text/plain;
	charset="us-ascii"
Content-Transfer-Encoding: 7bit

Help me on the code (VB) for a DropDownlist selectedIndex.
 
What I Have : 
 - (Inventory web Page---Sql database) - I have to change the owner and
the local were Hardware is placed in my institution . 
 - In a datagrid I have a Template column (with Itemtemplate and
EditItemTemplate)
 - In EditItemtemplate I have two DropDownlists so that I can change the
User and the local where Hardawre is .
- DropdownLists are populated with Dataviews :
           
  SUB PopulateMyDropDownList()
      Dim DataAdapter as SqlDataAdapter
      Dim Ds as New Dataset()
      Dim SelectCmd as String="Select num, STR(Num) + ' - ' + Nom as
Name from Table_inventory ORDER By Nom"
      DataAdapter = New SqlDataAdapter(SelectCmd, myconnection)
     dataAdapter.Fill(DS, "TempInfo")
      DropDownDataView = DS.Tables("TempInfo").defaultView
END SUB
      
It Works perfectly and I get my DropDownList Populated from the
database.
 
 
How do I get my DropDownList SelectedIndex?
 
WHAT I Tried doesn't work:
.........
    SelectedIndex= '<%# getNameIndex(Container.DataItem("Nom"))%>
........
 
 
Public Function getNameIndex(Name as String) As Integer
     Dim cRow as DataRow
     Dim Index as Int64=0
     for each cRow in dropdownDataview
       If Crow("Nom") = Name then
           Index=Crow("Num")
           exit for
       end If
     Next
 return Index
 
End Function
 
 
ERROR Returned : "Specified cast is not valid"
 
 
Thanks in advance,
 
Miguel Simoes
LISBOA - PORTUGAL


Message #3 by jdonahue@f... on Thu, 6 Jun 2002 17:47:34
Ooopss....in my stuff below "EmpPerm" should be substituted with 
<YourList>.  I cut and pasted some code of mine without specifying that 
EmpPerm is the name of my dropdown list....simply put the name of your 
drop down list wherever I have EmpPerm and <YourList>
-Jim

> If I understood all of this correctly, some of the info you can get is:
S> electedValue = EmpPerm.SelectedItem.Value
S> electedText = EmpPerm.SelectedItem.Text
S> electedIndex = <YourList>.Items.IndexOf(<YourList>.Items.FindByText
(> SelectedText))
S> electedIndex = <YourList>.Items.IndexOf(<YourList>.Items.FindByValue
(> SelectedValue))
-> Jim

> Session("TempEmpPermName") = EmpPerm.SelectedItem.Text

> > This is a multi-part message in MIME format.

> ------=_NextPart_000_0020_01C20CF0.44423830
C> ontent-Type: text/plain;
	> charset="us-ascii"
C> ontent-Transfer-Encoding: 7bit

> Help me on the code (VB) for a DropDownlist selectedIndex.
 > 
W> hat I Have : 
 > - (Inventory web Page---Sql database) - I have to change the owner and
t> he local were Hardware is placed in my institution . 
 > - In a datagrid I have a Template column (with Itemtemplate and
E> ditItemTemplate)
 > - In EditItemtemplate I have two DropDownlists so that I can change the
U> ser and the local where Hardawre is .
->  DropdownLists are populated with Dataviews :
 >           
 >  SUB PopulateMyDropDownList()
 >      Dim DataAdapter as SqlDataAdapter
 >      Dim Ds as New Dataset()
 >      Dim SelectCmd as String="Select num, STR(Num) + ' - ' + Nom as
N> ame from Table_inventory ORDER By Nom"
 >      DataAdapter = New SqlDataAdapter(SelectCmd, myconnection)
 >     dataAdapter.Fill(DS, "TempInfo")
 >      DropDownDataView = DS.Tables("TempInfo").defaultView
E> ND SUB
 >      
I> t Works perfectly and I get my DropDownList Populated from the
d> atabase.
 > 
 > 
H> ow do I get my DropDownList SelectedIndex?
 > 
W> HAT I Tried doesn't work:
.> ........
 >    SelectedIndex= '<%# getNameIndex(Container.DataItem("Nom"))%>
.> .......
 > 
 > 
P> ublic Function getNameIndex(Name as String) As Integer
 >     Dim cRow as DataRow
 >     Dim Index as Int64=0
 >     for each cRow in dropdownDataview
 >       If Crow("Nom") = Name then
 >           Index=Crow("Num")
 >           exit for
 >       end If
 >     Next
 > return Index
 > 
E> nd Function
 > 
 > 
E> RROR Returned : "Specified cast is not valid"
 > 
 > 
T> hanks in advance,
 > 
M> iguel Simoes
L> ISBOA - PORTUGAL

> ------=_NextPart_000_0020_01C20CF0.44423830
C> ontent-Type: text/html;
	> charset="us-ascii"
C> ontent-Transfer-Encoding: quoted-printable

> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<> HTML><HEAD>
<> META HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; 
c> harset=3Dus-ascii">
<> TITLE>Message</TITLE>

> <META content=3D"MSHTML 6.00.2715.400" name=3DGENERATOR></HEAD>
<> BODY>
<> DIV><FONT face=3DArial size=3D2>
<> DIV><SPAN class=3D652143622-05062002><FONT face=3DArial size=3D2>Help 
m> e on the code
(> VB) for a DropDownlist selectedIndex.</FONT></SPAN></DIV>
<> DIV><SPAN class=3D652143622-05062002><FONT face=3DArial
s> ize=3D2></FONT></SPAN>&nbsp;</DIV>
<> DIV><SPAN class=3D652143622-05062002><FONT face=3DArial size=3D2>What 
I 
H> ave :
<> /FONT></SPAN></DIV>
<> DIV><SPAN class=3D652143622-05062002><FONT face=3DArial 
s> ize=3D2>&nbsp;- (Inventory
w> eb Page---Sql database) - I have to change the owner and the local 
were 

> Hardware is placed in my institution . </FONT></SPAN></DIV>
<> DIV><SPAN class=3D652143622-05062002><FONT face=3DArial 
s> ize=3D2>&nbsp;- In a
d> atagrid I have a Template column (with Itemtemplate and
E> ditItemTemplate)</FONT></SPAN></DIV>
<> DIV><SPAN class=3D652143622-05062002><FONT face=3DArial 
s> ize=3D2>&nbsp;- In
E> ditItemtemplate I have two DropDownlists so that I can change the User 

a> nd the
l> ocal where Hardawre is .</FONT></SPAN></DIV>
<> DIV><SPAN class=3D652143622-05062002><FONT face=3DArial size=3D2>- 
D> ropdownLists are
p> opulated&nbsp;with Dataviews :</FONT></SPAN></DIV>
<> DIV><SPAN class=3D652143622-05062002><FONT face=3DArial
s> ize=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<> /FONT></SPAN></DIV>
<> DIV><SPAN class=3D652143622-05062002><FONT face=3DArial 
s> ize=3D2>&nbsp;&nbsp;SUB
P> opulateMyDropDownList()</FONT></SPAN></DIV>
<> DIV><SPAN class=3D652143622-05062002><FONT face=3DArial
s> ize=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim DataAdapter as
S> qlDataAdapter</FONT></SPAN></DIV>
<> DIV><SPAN class=3D652143622-05062002><FONT face=3DArial
s> ize=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim Ds as New
D> ataset()</FONT></SPAN></DIV>
<> DIV><SPAN class=3D652143622-05062002><FONT face=3DArial
s> ize=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim SelectCmd as 
S> tring=3D"Select num,
S> TR(Num) + ' - ' + Nom as Name from Table_inventory ORDER By
N> om"</FONT></SPAN></DIV>
<> DIV><SPAN class=3D652143622-05062002><FONT face=3DArial
s> ize=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DataAdapter =3D New
S> qlDataAdapter(SelectCmd, myconnection)</FONT></SPAN></DIV>
<> DIV><SPAN class=3D652143622-05062002><FONT face=3DArial
s> ize=3D2>&nbsp;&nbsp;&nbsp;&nbsp; dataAdapter.Fill(DS,
"> TempInfo")</FONT></SPAN></DIV>
<> DIV><SPAN class=3D652143622-05062002><FONT face=3DArial
s> ize=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DropDownDataView =3D
D> S.Tables("TempInfo").defaultView</FONT></SPAN></DIV>
<> DIV><SPAN class=3D652143622-05062002><FONT face=3DArial size=3D2>END
S> UB</FONT></SPAN></DIV>
<> DIV><SPAN class=3D652143622-05062002><FONT face=3DArial
s> ize=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </FONT></SPAN></DIV>
<> DIV><SPAN class=3D652143622-05062002><FONT face=3DArial size=3D2>It 
W> orks perfectly
a> nd I get my DropDownList Populated from the 
d> atabase.</FONT></SPAN></DIV>
<> DIV><SPAN class=3D652143622-05062002><FONT face=3DArial
s> ize=3D2></FONT></SPAN>&nbsp;</DIV>
<> DIV><SPAN class=3D652143622-05062002><FONT face=3DArial
s> ize=3D2></FONT></SPAN>&nbsp;</DIV>
<> DIV><SPAN class=3D652143622-05062002><FONT face=3DArial size=3D2>How 
do 
I>  get my
D> ropDownList SelectedIndex?</FONT></SPAN></DIV>
<> DIV><SPAN class=3D652143622-05062002><FONT face=3DArial
s> ize=3D2></FONT></SPAN>&nbsp;</DIV>
<> DIV><SPAN class=3D652143622-05062002><FONT face=3DArial size=3D2>WHAT 
I 
T> ried doesn't
w> ork:</FONT></SPAN></DIV>
<> DIV><SPAN class=3D652143622-05062002><FONT face=3DArial
s> ize=3D2>.........</FONT></SPAN></DIV>
<> DIV><SPAN class=3D652143622-05062002><FONT face=3DArial 
s> ize=3D2>&nbsp;&nbsp;&nbsp;
S> electedIndex=3D '&lt;%#
g> etNameIndex(Container.DataItem("Nom"))%&gt;</FONT></SPAN></DIV>
<> DIV><SPAN class=3D652143622-05062002><FONT face=3DArial
s> ize=3D2>........</FONT></SPAN></DIV>
<> DIV><SPAN class=3D652143622-05062002><FONT face=3DArial
s> ize=3D2></FONT></SPAN>&nbsp;</DIV>
<> DIV><SPAN class=3D652143622-05062002><FONT face=3DArial
s> ize=3D2></FONT></SPAN>&nbsp;</DIV>
<> DIV><SPAN class=3D652143622-05062002><FONT face=3DArial 
size=3D2>Public 
F> unction
g> etNameIndex(Name as String) As Integer</FONT></SPAN></DIV>
<> DIV><SPAN class=3D652143622-05062002><FONT face=3DArial
s> ize=3D2>&nbsp;&nbsp;&nbsp;&nbsp; Dim cRow as 
D> ataRow</FONT></SPAN></DIV>
<> DIV><SPAN class=3D652143622-05062002><FONT face=3DArial
s> ize=3D2>&nbsp;&nbsp;&nbsp;&nbsp; Dim Index as 
I> nt64=3D0</FONT></SPAN></DIV>
<> DIV><SPAN class=3D652143622-05062002><FONT face=3DArial
s> ize=3D2>&nbsp;&nbsp;&nbsp;&nbsp; for each cRow in
d> ropdownDataview</FONT></SPAN></DIV>
<> DIV><SPAN class=3D652143622-05062002><FONT face=3DArial
s> ize=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If Crow("Nom") =3D Name
t> hen</FONT></SPAN></DIV>
<> DIV><SPAN class=3D652143622-05062002><FONT face=3DArial
s> ize=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
I> ndex=3DCrow("Num")</FONT></SPAN></DIV>
<> DIV><SPAN class=3D652143622-05062002><FONT face=3DArial
s> ize=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
e> xit
f> or</FONT></SPAN></DIV>
<> DIV><SPAN class=3D652143622-05062002><FONT face=3DArial
s> ize=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; end If</FONT></SPAN></DIV>
<> DIV><SPAN class=3D652143622-05062002><FONT face=3DArial
s> ize=3D2>&nbsp;&nbsp;&nbsp;&nbsp; Next</FONT></SPAN></DIV>
<> DIV><SPAN class=3D652143622-05062002><FONT face=3DArial 
s> ize=3D2>&nbsp;return
I> ndex</FONT></SPAN></DIV>
<> DIV><SPAN class=3D652143622-05062002><FONT face=3DArial
s> ize=3D2></FONT></SPAN>&nbsp;</DIV>
<> DIV><SPAN class=3D652143622-05062002><FONT face=3DArial size=3D2>End
F> unction</FONT></SPAN></DIV>
<> DIV><SPAN class=3D652143622-05062002><FONT face=3DArial
s> ize=3D2></FONT></SPAN>&nbsp;</DIV>
<> DIV><SPAN class=3D652143622-05062002><FONT face=3DArial
s> ize=3D2></FONT></SPAN>&nbsp;</DIV>
<> DIV><SPAN class=3D652143622-05062002><FONT face=3DArial size=3D2>ERROR 

R> eturned :
"> Specified cast is not valid"</FONT></SPAN></DIV>
<> DIV><SPAN class=3D652143622-05062002><FONT face=3DArial
s> ize=3D2></FONT></SPAN>&nbsp;</DIV>
<> DIV><SPAN class=3D652143622-05062002><FONT face=3DArial
s> ize=3D2></FONT></SPAN>&nbsp;</DIV>
<> DIV><SPAN class=3D652143622-05062002><FONT face=3DArial 
size=3D2>Thanks 
i> n
a> dvance,</FONT></SPAN></DIV>
<> DIV><SPAN class=3D652143622-05062002><FONT face=3DArial
s> ize=3D2></FONT></SPAN>&nbsp;</DIV>
<> DIV><SPAN class=3D652143622-05062002><FONT face=3DArial 
size=3D2>Miguel 

> Simoes</FONT></SPAN></DIV>
<> DIV><SPAN class=3D652143622-05062002><FONT face=3DArial 
size=3D2>LISBOA 
-> 
P> ORTUGAL</FONT></SPAN></DIV></FONT></DIV></BODY></HTML>

> ------=_NextPart_000_0020_01C20CF0.44423830--

Message #4 by "Miguel Simoes" <mjsimoes@m...> on Wed, 5 Jun 2002 19:47:29 +0100
Sorry but I don't understand...What I want is when I click the Edit
button the Dropdownlist must show me the same item of the database (the
item I see (name) whem Edit button is not clicked)..I tried your
suggestion but it doesn't work...

Any other HELP?

Miguel Simoes
Lisboa - Portugal

-----Original Message-----
From: jdonahue@f... [mailto:jdonahue@f...] 
Sent: quinta-feira, 6 de Junho de 2002 17:48
To: aspx_beginners
Subject: [aspx_beginners] Re: DropDownList SelectedIndex (PLEASE HELP)


Ooopss....in my stuff below "EmpPerm" should be substituted with 
<YourList>.  I cut and pasted some code of mine without specifying that 
EmpPerm is the name of my dropdown list....simply put the name of your 
drop down list wherever I have EmpPerm and <YourList>
-Jim

> If I understood all of this correctly, some of the info you can get 
> is:
S> electedValue = EmpPerm.SelectedItem.Value
S> electedText = EmpPerm.SelectedItem.Text
S> electedIndex = <YourList>.Items.IndexOf(<YourList>.Items.FindByText
(> SelectedText))
S> electedIndex = <YourList>.Items.IndexOf(<YourList>.Items.FindByValue
(> SelectedValue))
-> Jim

> Session("TempEmpPermName") = EmpPerm.SelectedItem.Text

> > This is a multi-part message in MIME format.

> ------=_NextPart_000_0020_01C20CF0.44423830
C> ontent-Type: text/plain;
	> charset="us-ascii"
C> ontent-Transfer-Encoding: 7bit

> Help me on the code (VB) for a DropDownlist selectedIndex.
 > 
W> hat I Have :
 > - (Inventory web Page---Sql database) - I have to change the owner
and
t> he local were Hardware is placed in my institution .
 > - In a datagrid I have a Template column (with Itemtemplate and
E> ditItemTemplate)
 > - In EditItemtemplate I have two DropDownlists so that I can change
the
U> ser and the local where Hardawre is .
->  DropdownLists are populated with Dataviews :
 >           
 >  SUB PopulateMyDropDownList()
 >      Dim DataAdapter as SqlDataAdapter
 >      Dim Ds as New Dataset()
 >      Dim SelectCmd as String="Select num, STR(Num) + ' - ' + Nom as
N> ame from Table_inventory ORDER By Nom"
 >      DataAdapter = New SqlDataAdapter(SelectCmd, myconnection)
 >     dataAdapter.Fill(DS, "TempInfo")
 >      DropDownDataView = DS.Tables("TempInfo").defaultView
E> ND SUB
 >      
I> t Works perfectly and I get my DropDownList Populated from the
d> atabase.
 > 
 > 
H> ow do I get my DropDownList SelectedIndex?
 > 
W> HAT I Tried doesn't work:
.> ........
 >    SelectedIndex= '<%# getNameIndex(Container.DataItem("Nom"))%>
.> .......
 > 
 > 
P> ublic Function getNameIndex(Name as String) As Integer
 >     Dim cRow as DataRow
 >     Dim Index as Int64=0
 >     for each cRow in dropdownDataview
 >       If Crow("Nom") = Name then
 >           Index=Crow("Num")
 >           exit for
 >       end If
 >     Next
 > return Index
 > 
E> nd Function
 > 
 > 
E> RROR Returned : "Specified cast is not valid"
 > 
 > 
T> hanks in advance,
 > 
M> iguel Simoes
L> ISBOA - PORTUGAL

> ------=_NextPart_000_0020_01C20CF0.44423830
C> ontent-Type: text/html;
	> charset="us-ascii"
C> ontent-Transfer-Encoding: quoted-printable

> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<> HTML><HEAD>
<> META HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; 
c> harset=3Dus-ascii">
<> TITLE>Message</TITLE>

> <META content=3D"MSHTML 6.00.2715.400" name=3DGENERATOR></HEAD>
<> BODY>
<> DIV><FONT face=3DArial size=3D2>
<> DIV><SPAN class=3D652143622-05062002><FONT face=3DArial size=3D2>Help

m> e on the code
(> VB) for a DropDownlist selectedIndex.</FONT></SPAN></DIV>
<> DIV><SPAN class=3D652143622-05062002><FONT face=3DArial
s> ize=3D2></FONT></SPAN>&nbsp;</DIV>
<> DIV><SPAN class=3D652143622-05062002><FONT face=3DArial size=3D2>What

I 
H> ave :
<> /FONT></SPAN></DIV>
<> DIV><SPAN class=3D652143622-05062002><FONT face=3DArial 
s> ize=3D2>&nbsp;- (Inventory
w> eb Page---Sql database) - I have to change the owner and the local
were 

> Hardware is placed in my institution . </FONT></SPAN></DIV>
<> DIV><SPAN class=3D652143622-05062002><FONT face=3DArial 
s> ize=3D2>&nbsp;- In a
d> atagrid I have a Template column (with Itemtemplate and
E> ditItemTemplate)</FONT></SPAN></DIV>
<> DIV><SPAN class=3D652143622-05062002><FONT face=3DArial 
s> ize=3D2>&nbsp;- In
E> ditItemtemplate I have two DropDownlists so that I can change the
User 

a> nd the
l> ocal where Hardawre is .</FONT></SPAN></DIV>
<> DIV><SPAN class=3D652143622-05062002><FONT face=3DArial size=3D2>- 
D> ropdownLists are
p> opulated&nbsp;with Dataviews :</FONT></SPAN></DIV>
<> DIV><SPAN class=3D652143622-05062002><FONT face=3DArial
s>
ize=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<> /FONT></SPAN></DIV>
<> DIV><SPAN class=3D652143622-05062002><FONT face=3DArial 
s> ize=3D2>&nbsp;&nbsp;SUB
P> opulateMyDropDownList()</FONT></SPAN></DIV>
<> DIV><SPAN class=3D652143622-05062002><FONT face=3DArial
s> ize=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim DataAdapter as
S> qlDataAdapter</FONT></SPAN></DIV>
<> DIV><SPAN class=3D652143622-05062002><FONT face=3DArial
s> ize=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim Ds as New
D> ataset()</FONT></SPAN></DIV>
<> DIV><SPAN class=3D652143622-05062002><FONT face=3DArial
s> ize=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim SelectCmd as 
S> tring=3D"Select num,
S> TR(Num) + ' - ' + Nom as Name from Table_inventory ORDER By
N> om"</FONT></SPAN></DIV>
<> DIV><SPAN class=3D652143622-05062002><FONT face=3DArial
s> ize=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DataAdapter =3D New
S> qlDataAdapter(SelectCmd, myconnection)</FONT></SPAN></DIV>
<> DIV><SPAN class=3D652143622-05062002><FONT face=3DArial
s> ize=3D2>&nbsp;&nbsp;&nbsp;&nbsp; dataAdapter.Fill(DS,
"> TempInfo")</FONT></SPAN></DIV>
<> DIV><SPAN class=3D652143622-05062002><FONT face=3DArial
s> ize=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DropDownDataView =3D
D> S.Tables("TempInfo").defaultView</FONT></SPAN></DIV>
<> DIV><SPAN class=3D652143622-05062002><FONT face=3DArial
size=3D2>END
S> UB</FONT></SPAN></DIV>
<> DIV><SPAN class=3D652143622-05062002><FONT face=3DArial
s> ize=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </FONT></SPAN></DIV>
<> DIV><SPAN class=3D652143622-05062002><FONT face=3DArial size=3D2>It 
W> orks perfectly
a> nd I get my DropDownList Populated from the 
d> atabase.</FONT></SPAN></DIV>
<> DIV><SPAN class=3D652143622-05062002><FONT face=3DArial
s> ize=3D2></FONT></SPAN>&nbsp;</DIV>
<> DIV><SPAN class=3D652143622-05062002><FONT face=3DArial
s> ize=3D2></FONT></SPAN>&nbsp;</DIV>
<> DIV><SPAN class=3D652143622-05062002><FONT face=3DArial size=3D2>How 
do 
I>  get my
D> ropDownList SelectedIndex?</FONT></SPAN></DIV>
<> DIV><SPAN class=3D652143622-05062002><FONT face=3DArial
s> ize=3D2></FONT></SPAN>&nbsp;</DIV>
<> DIV><SPAN class=3D652143622-05062002><FONT face=3DArial size=3D2>WHAT

I 
T> ried doesn't
w> ork:</FONT></SPAN></DIV>
<> DIV><SPAN class=3D652143622-05062002><FONT face=3DArial
s> ize=3D2>.........</FONT></SPAN></DIV>
<> DIV><SPAN class=3D652143622-05062002><FONT face=3DArial 
s> ize=3D2>&nbsp;&nbsp;&nbsp;
S> electedIndex=3D '&lt;%#
g> etNameIndex(Container.DataItem("Nom"))%&gt;</FONT></SPAN></DIV>
<> DIV><SPAN class=3D652143622-05062002><FONT face=3DArial
s> ize=3D2>........</FONT></SPAN></DIV>
<> DIV><SPAN class=3D652143622-05062002><FONT face=3DArial
s> ize=3D2></FONT></SPAN>&nbsp;</DIV>
<> DIV><SPAN class=3D652143622-05062002><FONT face=3DArial
s> ize=3D2></FONT></SPAN>&nbsp;</DIV>
<> DIV><SPAN class=3D652143622-05062002><FONT face=3DArial 
size=3D2>Public 
F> unction
g> etNameIndex(Name as String) As Integer</FONT></SPAN></DIV>
<> DIV><SPAN class=3D652143622-05062002><FONT face=3DArial
s> ize=3D2>&nbsp;&nbsp;&nbsp;&nbsp; Dim cRow as 
D> ataRow</FONT></SPAN></DIV>
<> DIV><SPAN class=3D652143622-05062002><FONT face=3DArial
s> ize=3D2>&nbsp;&nbsp;&nbsp;&nbsp; Dim Index as 
I> nt64=3D0</FONT></SPAN></DIV>
<> DIV><SPAN class=3D652143622-05062002><FONT face=3DArial
s> ize=3D2>&nbsp;&nbsp;&nbsp;&nbsp; for each cRow in
d> ropdownDataview</FONT></SPAN></DIV>
<> DIV><SPAN class=3D652143622-05062002><FONT face=3DArial
s> ize=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If Crow("Nom") =3D
Name
t> hen</FONT></SPAN></DIV>
<> DIV><SPAN class=3D652143622-05062002><FONT face=3DArial
s>
ize=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
I> ndex=3DCrow("Num")</FONT></SPAN></DIV>
<> DIV><SPAN class=3D652143622-05062002><FONT face=3DArial
s> ize=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

e> xit
f> or</FONT></SPAN></DIV>
<> DIV><SPAN class=3D652143622-05062002><FONT face=3DArial
s> ize=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; end
If</FONT></SPAN></DIV>
<> DIV><SPAN class=3D652143622-05062002><FONT face=3DArial
s> ize=3D2>&nbsp;&nbsp;&nbsp;&nbsp; Next</FONT></SPAN></DIV>
<> DIV><SPAN class=3D652143622-05062002><FONT face=3DArial 
s> ize=3D2>&nbsp;return
I> ndex</FONT></SPAN></DIV>
<> DIV><SPAN class=3D652143622-05062002><FONT face=3DArial
s> ize=3D2></FONT></SPAN>&nbsp;</DIV>
<> DIV><SPAN class=3D652143622-05062002><FONT face=3DArial
size=3D2>End
F> unction</FONT></SPAN></DIV>
<> DIV><SPAN class=3D652143622-05062002><FONT face=3DArial
s> ize=3D2></FONT></SPAN>&nbsp;</DIV>
<> DIV><SPAN class=3D652143622-05062002><FONT face=3DArial
s> ize=3D2></FONT></SPAN>&nbsp;</DIV>
<> DIV><SPAN class=3D652143622-05062002><FONT face=3DArial
size=3D2>ERROR 

R> eturned :
"> Specified cast is not valid"</FONT></SPAN></DIV>
<> DIV><SPAN class=3D652143622-05062002><FONT face=3DArial
s> ize=3D2></FONT></SPAN>&nbsp;</DIV>
<> DIV><SPAN class=3D652143622-05062002><FONT face=3DArial
s> ize=3D2></FONT></SPAN>&nbsp;</DIV>
<> DIV><SPAN class=3D652143622-05062002><FONT face=3DArial 
size=3D2>Thanks 
i> n
a> dvance,</FONT></SPAN></DIV>
<> DIV><SPAN class=3D652143622-05062002><FONT face=3DArial
s> ize=3D2></FONT></SPAN>&nbsp;</DIV>
<> DIV><SPAN class=3D652143622-05062002><FONT face=3DArial 
size=3D2>Miguel 

> Simoes</FONT></SPAN></DIV>
<> DIV><SPAN class=3D652143622-05062002><FONT face=3DArial 
size=3D2>LISBOA 
-> 
P> ORTUGAL</FONT></SPAN></DIV></FONT></DIV></BODY></HTML>

> ------=_NextPart_000_0020_01C20CF0.44423830--


Message #5 by "Patterson, Stephanie L" <stephanie.l.patterson@i...> on Tue, 11 Jun 2002 13:38:27 -0700
I must be missing something.  I, too, am trying to get changed selected data
from MULTIPLE dropdownlists within either a DataGrid or DataList and send
the update back to a sql database.  I'm using VB. 

I've what you suggested, but I get the following error message:
Compiler Error Message: BC30456: 'value' is not a member of
'System.Web.UI.WebControls.DataGridItem'.


If I try it with a DataList instead of DataGrid, I get the following:
Compiler Error Message: BC30456: 'value' is not a member of
'System.Web.UI.WebControls.DataListItem'.

Any help is much appreciated!
Stephanie

-----Original Message-----
From: jdonahue@f... [mailto:jdonahue@f...]
Sent: Thursday, June 06, 2002 10:46 AM
To: aspx_beginners
Subject: [aspx_beginners] Re: DropDownList SelectedIndex (PLEASE HELP)


If I understood all of this correctly, some of the info you can get is:
SelectedValue = EmpPerm.SelectedItem.Value
SelectedText = EmpPerm.SelectedItem.Text
SelectedIndex = <YourList>.Items.IndexOf(<YourList>.Items.FindByText
(SelectedText))
SelectedIndex = <YourList>.Items.IndexOf(<YourList>.Items.FindByValue
(SelectedValue))
-Jim

Session("TempEmpPermName") = EmpPerm.SelectedItem.Text

> This is a multi-part message in MIME format.

------=_NextPart_000_0020_01C20CF0.44423830
Content-Type: text/plain;
	charset="us-ascii"
Content-Transfer-Encoding: 7bit

Help me on the code (VB) for a DropDownlist selectedIndex.
 
What I Have : 
 - (Inventory web Page---Sql database) - I have to change the owner and
the local were Hardware is placed in my institution . 
 - In a datagrid I have a Template column (with Itemtemplate and
EditItemTemplate)
 - In EditItemtemplate I have two DropDownlists so that I can change the
User and the local where Hardawre is .
- DropdownLists are populated with Dataviews :
           
  SUB PopulateMyDropDownList()
      Dim DataAdapter as SqlDataAdapter
      Dim Ds as New Dataset()
      Dim SelectCmd as String="Select num, STR(Num) + ' - ' + Nom as
Name from Table_inventory ORDER By Nom"
      DataAdapter = New SqlDataAdapter(SelectCmd, myconnection)
     dataAdapter.Fill(DS, "TempInfo")
      DropDownDataView = DS.Tables("TempInfo").defaultView
END SUB
      
It Works perfectly and I get my DropDownList Populated from the
database.
 
 
How do I get my DropDownList SelectedIndex?
 
WHAT I Tried doesn't work:
.........
    SelectedIndex= '<%# getNameIndex(Container.DataItem("Nom"))%>
........
 
 
Public Function getNameIndex(Name as String) As Integer
     Dim cRow as DataRow
     Dim Index as Int64=0
     for each cRow in dropdownDataview
       If Crow("Nom") = Name then
           Index=Crow("Num")
           exit for
       end If
     Next
 return Index
 
End Function
 
 
ERROR Returned : "Specified cast is not valid"
 
 
Thanks in advance,
 
Miguel Simoes
LISBOA - PORTUGAL



  Return to Index