This message was discovered on ASPFriends.com 'aspngescalate' list.
| =?iso-8859-1?Q?Andr=E9_Colbi=F6rnsen?= |
I would think that using an ItemTemplate Column and an EditTemplate is what you need:
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D ASPX =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D <asp:TemplateColumn> <ItemTemplate> <%# Container.DataItem( "headline" ) %> </ItemTemplate> <EditItemTemplate> <asp:DropDownList ID=3DmyDrop Runat=3Dserver /> </EditItemTemplate> </asp:TemplateColumn>
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
Then you use the 'DataGrid_ItemDataBound' to fill the DropDown at runtime:
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D CODEBEHIND =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
Sub DataGrid_ItemDataBound(ByVal s As Object, ByVal e As DataGridItemEventArgs) Dim conFamily As SqlConnection =3D New SqlConnection(strConn) Dim myReader As SqlDataReader Dim itemType As ListItemType =3D e.Item.ItemType If (itemType =3D ListItemType.Item Or itemType =3D ListItemType.AlternatingItem) Then Dim myDrop As DropDownList =3D CType(e.Item.FindControl("myDrop"), DropDownList )
'If you are getting your value fr your query else=20 'you will have to get this in aseparate query =09 '----------------------------------------------------------------------- -------- Dim yrValue As Value =3D e.Item.DataItem("yrValue")
Dim cmdSelect As New SqlCommand("Select * From Table Order by yrOrder", conFamily)
conn.Open()
'Fill the dropdown '-------------------------------- myReader =3D cmdSelect4.ExecuteReader()
myDrop.DataSource =3D dtrReg myDrop.DataValueField =3D "prioritetID" myDrop.DataTextField =3D "prioritet" myDrop.DataBind() myDrop.Items.Insert(0, yrValue) myDrop.SelectedIndex =3D 0 myReader .Close() conn.Open() End If End Sub 'DataGrid_ItemDataBound
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
Do the same in the Update sub; Find the control, read the value/text and update your database I haven't tested this but it should be pretty straight forward. Hope it at least gives you an idea.
Regards/Halsningar
Andre Colbiornsen -------------------------------------- Sonnenburg Communications Bergsgatan 3, SE-211 54 Malm=F6 Sweden Tel.: +46-(0)40-97 78 80 Fax.: +46-(0)40-97 78 80 Mob.: +46-(0)708-97 78 79 Mail: Click here to reveal e-mail address Web.: www.sonnenburg.se -------------------------------------- B2B Web agency - Specializing on .Net --------------------------------------
-----Ursprungligt meddelande----- Fr=E5n: Jason Wisdom [mailto:Click here to reveal e-mail address]=20 Skickat: den 6 juni 2002 19:33 Till: aspngescalate =C4mne: [aspngescalate] Editable DropDownList in Datagrid - 3rd time asking
-- Moved from [aspngdata] to [aspngescalate] by Marcie Jones <Click here to reveal e-mail address> --
Hi, this got posted to aspngdatagridrepeaterdatalist twice, but there were no replies.
Has anybody used a dropdownlist in a datagrid edit mode? I have seen examples on the web and in books, but have not gotten any of them to work.
I am using VB.NET, with an .aspx and .aspx.vb files (code in 2nd file). I am trying to do the following:
- read a code table from SQL Server 2000 into a dropdownlist - have the dropdownlist only appear when "Edit" is chosen and only in the edited row - have the current value appear as the default choice in the dropdownlist - when hitting "Save", read its value for the UPDATE statement.
pretty standard stuff....=3D20
Any ideas? Thank you if you can help.
Jason | [aspngescalate] member Click here to reveal e-mail address =3D YOUR ID=20 | http://www.asplists.com/asplists/aspngescalate.asp =3D JOIN/QUIT
|
|
| |
| |
| Jason Wisdom |
Thank you both Martin and Andre,
I now have my dropdownlists populating in the datagrid when "Edit" is selected. That's great, except for one detail: The value isn't synching up. The first item is always selected.
Here is what I have ("reader" is the SqlDataReader object with the SELECT statement):
myDropUser.DataSource =3D reader myDropUser.DataValueField =3D "user_id" myDropUser.DataTextField =3D "user_nm" 'myDropUser.SelectedIndex =3D 0 'myDropUser.SelectedIndex =3D CInt(CType(e.Item.Cells(4).Controls(0), TextBox).Text) myDropUser.DataBind() reader.Close()
When I set "myDropUser.SelectedIndex =3D 0", the first item in the dropdownlist is selected upon Edit.
When I set "myDropUser.SelectedIndex =3D CInt(CType(e.Item.Cells(4).Controls(0), Textbox).Text), then the "user_id"th item is chosen (if user_id=3D6, then the 7th item is chosen...if user_id=3D1, the 2nd item is chosen...user_id cannot =3D 0 = as it is a SQL2000 identity field)
How do I set myDropUser.SelectedIndex =3D (the choice where user_id =3D = the already-chosen user_id for the record)?
Thank you SO much if you can answer this.
Jason
-----Original Message----- From: Andr=E9 Colbi=F6rnsen [mailto:Click here to reveal e-mail address] Sent: Thursday, June 06, 2002 12:57 PM To: aspngescalate Subject: [aspngescalate] SV: Editable DropDownList in Datagrid - 3rd time asking
I would think that using an ItemTemplate Column and an EditTemplate is what you need:
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D ASPX =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D <asp:TemplateColumn> <ItemTemplate> <%# Container.DataItem( "headline" ) %> </ItemTemplate> <EditItemTemplate> <asp:DropDownList ID=3DmyDrop Runat=3Dserver /> </EditItemTemplate> </asp:TemplateColumn>
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
Then you use the 'DataGrid_ItemDataBound' to fill the DropDown at runtime:
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D CODEBEHIND =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
Sub DataGrid_ItemDataBound(ByVal s As Object, ByVal e As DataGridItemEventArgs) Dim conFamily As SqlConnection =3D New SqlConnection(strConn) Dim myReader As SqlDataReader Dim itemType As ListItemType =3D e.Item.ItemType If (itemType =3D ListItemType.Item Or itemType =3D ListItemType.AlternatingItem) Then Dim myDrop As DropDownList =3D CType(e.Item.FindControl("myDrop"), DropDownList )
'If you are getting your value fr your query else=20 'you will have to get this in aseparate query =09 '----------------------------------------------------------------------- -------- Dim yrValue As Value =3D e.Item.DataItem("yrValue")
Dim cmdSelect As New SqlCommand("Select * From Table Order by yrOrder", conFamily)
conn.Open()
'Fill the dropdown '-------------------------------- myReader =3D cmdSelect4.ExecuteReader()
myDrop.DataSource =3D dtrReg myDrop.DataValueField =3D "prioritetID" myDrop.DataTextField =3D "prioritet" myDrop.DataBind() myDrop.Items.Insert(0, yrValue) myDrop.SelectedIndex =3D 0 myReader .Close() conn.Open() End If End Sub 'DataGrid_ItemDataBound
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
Do the same in the Update sub; Find the control, read the value/text and update your database I haven't tested this but it should be pretty straight forward. Hope it at least gives you an idea.
Regards/Halsningar
Andre Colbiornsen -------------------------------------- Sonnenburg Communications Bergsgatan 3, SE-211 54 Malm=F6 Sweden Tel.: +46-(0)40-97 78 80 Fax.: +46-(0)40-97 78 80 Mob.: +46-(0)708-97 78 79 Mail: Click here to reveal e-mail address Web.: www.sonnenburg.se -------------------------------------- B2B Web agency - Specializing on .Net --------------------------------------
-----Ursprungligt meddelande----- Fr=E5n: Jason Wisdom [mailto:Click here to reveal e-mail address]=20 Skickat: den 6 juni 2002 19:33 Till: aspngescalate =C4mne: [aspngescalate] Editable DropDownList in Datagrid - 3rd time asking
-- Moved from [aspngdata] to [aspngescalate] by Marcie Jones <Click here to reveal e-mail address> --
Hi, this got posted to aspngdatagridrepeaterdatalist twice, but there were no replies.
Has anybody used a dropdownlist in a datagrid edit mode? I have seen examples on the web and in books, but have not gotten any of them to work.
I am using VB.NET, with an .aspx and .aspx.vb files (code in 2nd file). I am trying to do the following:
- read a code table from SQL Server 2000 into a dropdownlist - have the dropdownlist only appear when "Edit" is chosen and only in the edited row - have the current value appear as the default choice in the dropdownlist - when hitting "Save", read its value for the UPDATE statement.
pretty standard stuff....=3D20
Any ideas? Thank you if you can help.
Jason | [aspngescalate] member Click here to reveal e-mail address =3D YOUR ID=20 | http://www.asplists.com/asplists/aspngescalate.asp =3D JOIN/QUIT
| [aspngescalate] member Click here to reveal e-mail address =3D YOUR ID | http://www.asplists.com/asplists/aspngescalate.asp =3D JOIN/QUIT
|
|
| |
|
| |
| Martin Garins |
I would not use SelectedIndex I would use SelectItemByValue
The Index of the DropDown is 0 based and will be 0 to the number of = items in your DropDown
Whereas the Value will be your User_id Which is not always 1 to some = number without any values missing
Martin Garins, MCSD Vice President - Technology e-Intersect Corp. http://www.e-intersect.com http://www.jppex.com
-----Original Message----- From: Jason Wisdom [mailto:Click here to reveal e-mail address]=20 Sent: Friday, June 07, 2002 2:53 PM To: aspngescalate Subject: [aspngescalate] RE: SV: Editable DropDownList in Datagrid - 3rd = time asking
Thank you both Martin and Andre,
I now have my dropdownlists populating in the datagrid when "Edit" is = selected. That's great, except for one detail: The value isn't = synching up. The first item is always selected.
Here is what I have ("reader" is the SqlDataReader object with the = SELECT statement):
myDropUser.DataSource =3D reader myDropUser.DataValueField =3D "user_id" myDropUser.DataTextField =3D "user_nm" 'myDropUser.SelectedIndex =3D 0 'myDropUser.SelectedIndex =3D = CInt(CType(e.Item.Cells(4).Controls(0), TextBox).Text) myDropUser.DataBind() reader.Close()
When I set "myDropUser.SelectedIndex =3D 0", the first item in the = dropdownlist is selected upon Edit.
When I set "myDropUser.SelectedIndex =3D = CInt(CType(e.Item.Cells(4).Controls(0), Textbox).Text), then the = "user_id"th item is chosen (if user_id=3D6, then the 7th item is = chosen...if user_id=3D1, the 2nd item is chosen...user_id cannot =3D 0 = as it is a SQL2000 identity field)
How do I set myDropUser.SelectedIndex =3D (the choice where user_id =3D = the already-chosen user_id for the record)?
Thank you SO much if you can answer this.
Jason
-----Original Message----- From: Andr=E9 Colbi=F6rnsen [mailto:Click here to reveal e-mail address] Sent: Thursday, June 06, 2002 12:57 PM To: aspngescalate Subject: [aspngescalate] SV: Editable DropDownList in Datagrid - 3rd = time asking
I would think that using an ItemTemplate Column and an EditTemplate is = what you need:
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D ASPX = =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D <asp:TemplateColumn> <ItemTemplate> <%# Container.DataItem( "headline" ) %> </ItemTemplate> <EditItemTemplate> <asp:DropDownList ID=3DmyDrop Runat=3Dserver /> </EditItemTemplate> </asp:TemplateColumn>
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
Then you use the 'DataGrid_ItemDataBound' to fill the DropDown at runtime:
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D CODEBEHIND = =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
Sub DataGrid_ItemDataBound(ByVal s As Object, ByVal e As DataGridItemEventArgs) Dim conFamily As SqlConnection =3D New SqlConnection(strConn) Dim myReader As SqlDataReader Dim itemType As ListItemType =3D e.Item.ItemType If (itemType =3D ListItemType.Item Or itemType =3D ListItemType.AlternatingItem) Then Dim myDrop As DropDownList =3D CType(e.Item.FindControl("myDrop"), DropDownList )
'If you are getting your value fr your query else=20 'you will have to get this in aseparate query =09 '----------------------------------------------------------------------- -------- Dim yrValue As Value =3D e.Item.DataItem("yrValue")
Dim cmdSelect As New SqlCommand("Select * From Table Order by yrOrder", = conFamily)
conn.Open()
'Fill the dropdown '-------------------------------- myReader =3D cmdSelect4.ExecuteReader()
myDrop.DataSource =3D dtrReg myDrop.DataValueField =3D "prioritetID" myDrop.DataTextField =3D "prioritet" myDrop.DataBind() myDrop.Items.Insert(0, yrValue) myDrop.SelectedIndex =3D 0 myReader .Close() conn.Open() End If End Sub 'DataGrid_ItemDataBound
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
Do the same in the Update sub; Find the control, read the value/text and = update your database I haven't tested this but it should be pretty = straight forward. Hope it at least gives you an idea.
Regards/Halsningar
Andre Colbiornsen -------------------------------------- Sonnenburg Communications Bergsgatan 3, SE-211 54 Malm=F6 Sweden Tel.: +46-(0)40-97 78 80 Fax.: +46-(0)40-97 78 80 Mob.: +46-(0)708-97 78 79 Mail: Click here to reveal e-mail address Web.: www.sonnenburg.se -------------------------------------- B2B Web agency - Specializing on .Net --------------------------------------
-----Ursprungligt meddelande----- Fr=E5n: Jason Wisdom [mailto:Click here to reveal e-mail address]=20 Skickat: den 6 juni 2002 19:33 Till: aspngescalate =C4mne: [aspngescalate] Editable DropDownList in Datagrid - 3rd time = asking
-- Moved from [aspngdata] to [aspngescalate] by Marcie Jones = <Click here to reveal e-mail address> --
Hi, this got posted to aspngdatagridrepeaterdatalist twice, but there = were no replies.
Has anybody used a dropdownlist in a datagrid edit mode? I have seen = examples on the web and in books, but have not gotten any of them to = work.
I am using VB.NET, with an .aspx and .aspx.vb files (code in 2nd file). = I am trying to do the following:
- read a code table from SQL Server 2000 into a dropdownlist - have the dropdownlist only appear when "Edit" is chosen and only in = the edited row - have the current value appear as the default choice in the = dropdownlist - when hitting "Save", read its value for the UPDATE statement.
pretty standard stuff....=3D20
Any ideas? Thank you if you can help.
Jason | [aspngescalate] member Click here to reveal e-mail address =3D YOUR ID | http://www.asplists.com/asplists/aspngescalate.asp =3D JOIN/QUIT
| [aspngescalate] member Click here to reveal e-mail address =3D YOUR ID | http://www.asplists.com/asplists/aspngescalate.asp =3D JOIN/QUIT
| [aspngescalate] member Click here to reveal e-mail address =3D YOUR ID | http://www.asplists.com/asplists/aspngescalate.asp =3D JOIN/QUIT
|
|
| |
|
| |
| Jason Wisdom |
Thanks Martin,
I can't find a "SelectItemByValue" method for the myDropUser item. It's not in the VStudio.NET Search or on MSDN.
myDropUser.SelectItemByValue is not recognized.
I tried using...
myDropUser.SelectedItem =3D CInt(CType(e.Item.Cells(4).Controls(0), TextBox).Text)
but I got a "c:\inetpub\wwwroot\iPort\Admin\manageUsersChannel.aspx.vb(172): Property 'SelectedItem' is 'ReadOnly'." error.
Is there a common syntax for this command? Thanks again. Jason
-----Original Message----- From: Martin Garins [mailto:Click here to reveal e-mail address] Sent: Friday, June 07, 2002 3:17 PM To: aspngescalate Subject: [aspngescalate] RE: SV: Editable DropDownList in Datagrid - 3rd time asking
I would not use SelectedIndex I would use SelectItemByValue
The Index of the DropDown is 0 based and will be 0 to the number of items in your DropDown
Whereas the Value will be your User_id Which is not always 1 to some number without any values missing
Martin Garins, MCSD Vice President - Technology e-Intersect Corp. http://www.e-intersect.com http://www.jppex.com
-----Original Message----- From: Jason Wisdom [mailto:Click here to reveal e-mail address]=20 Sent: Friday, June 07, 2002 2:53 PM To: aspngescalate Subject: [aspngescalate] RE: SV: Editable DropDownList in Datagrid - 3rd time asking
Thank you both Martin and Andre,
I now have my dropdownlists populating in the datagrid when "Edit" is selected. That's great, except for one detail: The value isn't synching up. The first item is always selected.
Here is what I have ("reader" is the SqlDataReader object with the SELECT statement):
myDropUser.DataSource =3D reader myDropUser.DataValueField =3D "user_id" myDropUser.DataTextField =3D "user_nm" 'myDropUser.SelectedIndex =3D 0 'myDropUser.SelectedIndex =3D CInt(CType(e.Item.Cells(4).Controls(0), TextBox).Text) myDropUser.DataBind() reader.Close()
When I set "myDropUser.SelectedIndex =3D 0", the first item in the dropdownlist is selected upon Edit.
When I set "myDropUser.SelectedIndex =3D CInt(CType(e.Item.Cells(4).Controls(0), Textbox).Text), then the "user_id"th item is chosen (if user_id=3D6, then the 7th item is chosen...if user_id=3D1, the 2nd item is chosen...user_id cannot =3D 0 = as it is a SQL2000 identity field)
How do I set myDropUser.SelectedIndex =3D (the choice where user_id =3D = the already-chosen user_id for the record)?
Thank you SO much if you can answer this.
Jason
-----Original Message----- From: Andr=E9 Colbi=F6rnsen [mailto:Click here to reveal e-mail address] Sent: Thursday, June 06, 2002 12:57 PM To: aspngescalate Subject: [aspngescalate] SV: Editable DropDownList in Datagrid - 3rd time asking
I would think that using an ItemTemplate Column and an EditTemplate is what you need:
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D ASPX =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D <asp:TemplateColumn> <ItemTemplate> <%# Container.DataItem( "headline" ) %> </ItemTemplate> <EditItemTemplate> <asp:DropDownList ID=3DmyDrop Runat=3Dserver /> </EditItemTemplate> </asp:TemplateColumn>
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
Then you use the 'DataGrid_ItemDataBound' to fill the DropDown at runtime:
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D CODEBEHIND =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
Sub DataGrid_ItemDataBound(ByVal s As Object, ByVal e As DataGridItemEventArgs) Dim conFamily As SqlConnection =3D New SqlConnection(strConn) Dim myReader As SqlDataReader Dim itemType As ListItemType =3D e.Item.ItemType If (itemType =3D ListItemType.Item Or itemType =3D ListItemType.AlternatingItem) Then Dim myDrop As DropDownList =3D CType(e.Item.FindControl("myDrop"), DropDownList )
'If you are getting your value fr your query else=20 'you will have to get this in aseparate query =09 '----------------------------------------------------------------------- -------- Dim yrValue As Value =3D e.Item.DataItem("yrValue")
Dim cmdSelect As New SqlCommand("Select * From Table Order by yrOrder", conFamily)
conn.Open()
'Fill the dropdown '-------------------------------- myReader =3D cmdSelect4.ExecuteReader()
myDrop.DataSource =3D dtrReg myDrop.DataValueField =3D "prioritetID" myDrop.DataTextField =3D "prioritet" myDrop.DataBind() myDrop.Items.Insert(0, yrValue) myDrop.SelectedIndex =3D 0 myReader .Close() conn.Open() End If End Sub 'DataGrid_ItemDataBound
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
Do the same in the Update sub; Find the control, read the value/text and update your database I haven't tested this but it should be pretty straight forward. Hope it at least gives you an idea.
Regards/Halsningar
Andre Colbiornsen -------------------------------------- Sonnenburg Communications Bergsgatan 3, SE-211 54 Malm=F6 Sweden Tel.: +46-(0)40-97 78 80 Fax.: +46-(0)40-97 78 80 Mob.: +46-(0)708-97 78 79 Mail: Click here to reveal e-mail address Web.: www.sonnenburg.se -------------------------------------- B2B Web agency - Specializing on .Net --------------------------------------
-----Ursprungligt meddelande----- Fr=E5n: Jason Wisdom [mailto:Click here to reveal e-mail address]=20 Skickat: den 6 juni 2002 19:33 Till: aspngescalate =C4mne: [aspngescalate] Editable DropDownList in Datagrid - 3rd time asking
-- Moved from [aspngdata] to [aspngescalate] by Marcie Jones <Click here to reveal e-mail address> --
Hi, this got posted to aspngdatagridrepeaterdatalist twice, but there were no replies.
Has anybody used a dropdownlist in a datagrid edit mode? I have seen examples on the web and in books, but have not gotten any of them to work.
I am using VB.NET, with an .aspx and .aspx.vb files (code in 2nd file). I am trying to do the following:
- read a code table from SQL Server 2000 into a dropdownlist - have the dropdownlist only appear when "Edit" is chosen and only in the edited row - have the current value appear as the default choice in the dropdownlist - when hitting "Save", read its value for the UPDATE statement.
pretty standard stuff....=3D20
Any ideas? Thank you if you can help.
Jason | [aspngescalate] member Click here to reveal e-mail address =3D YOUR ID | http://www.asplists.com/asplists/aspngescalate.asp =3D JOIN/QUIT
| [aspngescalate] member Click here to reveal e-mail address =3D YOUR ID | http://www.asplists.com/asplists/aspngescalate.asp =3D JOIN/QUIT
| [aspngescalate] member Click here to reveal e-mail address =3D YOUR ID | http://www.asplists.com/asplists/aspngescalate.asp =3D JOIN/QUIT
| [aspngescalate] member Click here to reveal e-mail address =3D YOUR ID | http://www.asplists.com/asplists/aspngescalate.asp =3D JOIN/QUIT
|
|
| |
|
| |
| Martin Garins |
I am sorry .. Most of my dropdown boxes are controls that I inherits = from Dropdown to make coding easier for databound dropdowns = SelectItemByValue is my method that does the following
Public Function SelectItemByValue(ByVal Value As String) Me.ClearSelection() Dim li As ListItem =3D Me.Items.FindByValue(Value) If Not (li Is Nothing) Then li.Selected =3D True End If End Function
So you really want yourcontrol.items.FindByValue
I hope this helps.
Martin Garins, MCSD Vice President - Technology e-Intersect Corp. http://www.e-intersect.com http://www.jppex.com
-----Original Message----- From: Jason Wisdom [mailto:Click here to reveal e-mail address]=20 Sent: Friday, June 07, 2002 5:41 PM To: aspngescalate Subject: [aspngescalate] RE: SV: Editable DropDownList in Datagrid - 3rd = time asking
Thanks Martin,
I can't find a "SelectItemByValue" method for the myDropUser item. It's = not in the VStudio.NET Search or on MSDN.
myDropUser.SelectItemByValue is not recognized.
I tried using...
myDropUser.SelectedItem =3D CInt(CType(e.Item.Cells(4).Controls(0), TextBox).Text)
but I got a "c:\inetpub\wwwroot\iPort\Admin\manageUsersChannel.aspx.vb(172): Property 'SelectedItem' is 'ReadOnly'." error.
Is there a common syntax for this command? Thanks again. Jason
-----Original Message----- From: Martin Garins [mailto:Click here to reveal e-mail address] Sent: Friday, June 07, 2002 3:17 PM To: aspngescalate Subject: [aspngescalate] RE: SV: Editable DropDownList in Datagrid - 3rd = time asking
I would not use SelectedIndex I would use SelectItemByValue
The Index of the DropDown is 0 based and will be 0 to the number of = items in your DropDown
Whereas the Value will be your User_id Which is not always 1 to some = number without any values missing
Martin Garins, MCSD Vice President - Technology e-Intersect Corp. http://www.e-intersect.com http://www.jppex.com
-----Original Message----- From: Jason Wisdom [mailto:Click here to reveal e-mail address]=20 Sent: Friday, June 07, 2002 2:53 PM To: aspngescalate Subject: [aspngescalate] RE: SV: Editable DropDownList in Datagrid - 3rd = time asking
Thank you both Martin and Andre,
I now have my dropdownlists populating in the datagrid when "Edit" is = selected. That's great, except for one detail: The value isn't = synching up. The first item is always selected.
Here is what I have ("reader" is the SqlDataReader object with the = SELECT statement):
myDropUser.DataSource =3D reader myDropUser.DataValueField =3D "user_id" myDropUser.DataTextField =3D "user_nm" 'myDropUser.SelectedIndex =3D 0 'myDropUser.SelectedIndex =3D = CInt(CType(e.Item.Cells(4).Controls(0), TextBox).Text) myDropUser.DataBind() reader.Close()
When I set "myDropUser.SelectedIndex =3D 0", the first item in the = dropdownlist is selected upon Edit.
When I set "myDropUser.SelectedIndex =3D = CInt(CType(e.Item.Cells(4).Controls(0), Textbox).Text), then the = "user_id"th item is chosen (if user_id=3D6, then the 7th item is = chosen...if user_id=3D1, the 2nd item is chosen...user_id cannot =3D 0 = as it is a SQL2000 identity field)
How do I set myDropUser.SelectedIndex =3D (the choice where user_id =3D = the already-chosen user_id for the record)?
Thank you SO much if you can answer this.
Jason
-----Original Message----- From: Andr=E9 Colbi=F6rnsen [mailto:Click here to reveal e-mail address] Sent: Thursday, June 06, 2002 12:57 PM To: aspngescalate Subject: [aspngescalate] SV: Editable DropDownList in Datagrid - 3rd = time asking
I would think that using an ItemTemplate Column and an EditTemplate is = what you need:
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D ASPX = =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D <asp:TemplateColumn> <ItemTemplate> <%# Container.DataItem( "headline" ) %> </ItemTemplate> <EditItemTemplate> <asp:DropDownList ID=3DmyDrop Runat=3Dserver /> </EditItemTemplate> </asp:TemplateColumn>
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
Then you use the 'DataGrid_ItemDataBound' to fill the DropDown at runtime:
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D CODEBEHIND = =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
Sub DataGrid_ItemDataBound(ByVal s As Object, ByVal e As DataGridItemEventArgs) Dim conFamily As SqlConnection =3D New SqlConnection(strConn) Dim myReader As SqlDataReader Dim itemType As ListItemType =3D e.Item.ItemType If (itemType =3D ListItemType.Item Or itemType =3D ListItemType.AlternatingItem) Then Dim myDrop As DropDownList =3D CType(e.Item.FindControl("myDrop"), DropDownList )
'If you are getting your value fr your query else=20 'you will have to get this in aseparate query =09 '----------------------------------------------------------------------- -------- Dim yrValue As Value =3D e.Item.DataItem("yrValue")
Dim cmdSelect As New SqlCommand("Select * From Table Order by yrOrder", = conFamily)
conn.Open()
'Fill the dropdown '-------------------------------- myReader =3D cmdSelect4.ExecuteReader()
myDrop.DataSource =3D dtrReg myDrop.DataValueField =3D "prioritetID" myDrop.DataTextField =3D "prioritet" myDrop.DataBind() myDrop.Items.Insert(0, yrValue) myDrop.SelectedIndex =3D 0 myReader .Close() conn.Open() End If End Sub 'DataGrid_ItemDataBound
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
Do the same in the Update sub; Find the control, read the value/text and = update your database I haven't tested this but it should be pretty = straight forward. Hope it at least gives you an idea.
Regards/Halsningar
Andre Colbiornsen -------------------------------------- Sonnenburg Communications Bergsgatan 3, SE-211 54 Malm=F6 Sweden Tel.: +46-(0)40-97 78 80 Fax.: +46-(0)40-97 78 80 Mob.: +46-(0)708-97 78 79 Mail: Click here to reveal e-mail address Web.: www.sonnenburg.se -------------------------------------- B2B Web agency - Specializing on .Net --------------------------------------
-----Ursprungligt meddelande----- Fr=E5n: Jason Wisdom [mailto:Click here to reveal e-mail address]=20 Skickat: den 6 juni 2002 19:33 Till: aspngescalate =C4mne: [aspngescalate] Editable DropDownList in Datagrid - 3rd time = asking
-- Moved from [aspngdata] to [aspngescalate] by Marcie Jones = <Click here to reveal e-mail address> --
Hi, this got posted to aspngdatagridrepeaterdatalist twice, but there = were no replies.
Has anybody used a dropdownlist in a datagrid edit mode? I have seen = examples on the web and in books, but have not gotten any of them to = work.
I am using VB.NET, with an .aspx and .aspx.vb files (code in 2nd file). = I am trying to do the following:
- read a code table from SQL Server 2000 into a dropdownlist - have the dropdownlist only appear when "Edit" is chosen and only in = the edited row - have the current value appear as the default choice in the = dropdownlist - when hitting "Save", read its value for the UPDATE statement.
pretty standard stuff....=3D20
Any ideas? Thank you if you can help.
Jason | [aspngescalate] member Click here to reveal e-mail address =3D YOUR ID=20 | http://www.asplists.com/asplists/aspngescalate.asp =3D JOIN/QUIT
| [aspngescalate] member Click here to reveal e-mail address =3D YOUR ID=20 | http://www.asplists.com/asplists/aspngescalate.asp =3D JOIN/QUIT
| [aspngescalate] member Click here to reveal e-mail address =3D YOUR ID=20 | http://www.asplists.com/asplists/aspngescalate.asp =3D JOIN/QUIT
| [aspngescalate] member Click here to reveal e-mail address =3D YOUR ID=20 | http://www.asplists.com/asplists/aspngescalate.asp =3D JOIN/QUIT
| [aspngescalate] member Click here to reveal e-mail address =3D YOUR ID=20 | http://www.asplists.com/asplists/aspngescalate.asp =3D JOIN/QUIT
|
|
| |
|
| |
| Jason Wisdom |
Hi all, thank you again Andre, Andre and Martin for your answers.
OK, it FINALLY seems I will be able to get this to work. But there has got to be a simpler way than how I'm doing it.
I tried each of your suggestions:
Martin G - Me.Items.FindByValue(Value) always seems to return Nothing. Even when in the Immediate Window I type in the same line with a value I know exists...I get Nothing back. Same when I code it in and place a watch on my ListItem. Your way seems like it would be the simplest - this is what I tried:
myDropUser.DataSource =3D reader myDropUser.DataValueField =3D "user_id" myDropUser.DataTextField =3D "user_nm" myDropUser.ClearSelection() Dim myListItem As ListItem =3D myDropUser.Items.FindByValue(CStr(CType(e.Item.Cells(4).Controls(0), TextBox).Text)) ' =3D "2" If Not (myListItem Is Nothing) Then myListItem.Selected =3D True End If myDropUser.DataBind()
Andre P. - When populating the DDLs, SelectedItem.Value by itself does not return anything, as nothing is selected. But it is turning out to be useful when I Save my changes, as that's how I'm reading the value. So that saves the next question I was going to ask.
Andre C. - I tried running these lines - ... myDropUser.DataBind() myDropUser.Items.Insert(0, "asdf") myDropUser.SelectedIndex =3D 0 myDropUser.SelectedItem.Value =3D = CInt(CType(e.Item.Cells(4).Controls(0), TextBox).Text) myDropUser.SelectedItem.Text =3D CStr(CType(e.Item.Cells(7).Controls(0), TextBox).Text) reader.Close()
This works! Great, thank you. But there are 2 things I'd like to smooth out: 1) The pre-selected item is duplicated and inserted before any other records. Is there any way to just select the desired item without creating a new dropdownlist record and going through all that? For example, if there are 7 Usernames, and I want the 5th with id=3D47 and name=3D"Jason", is there any way I can just say (go to the record with id=3D47)? That's what I'm really trying to do here. 2) In the .aspx file I'm working on presently, there are 3 columns with dropdownlists. Right now I have to do a whole CType formula on another column to get the id, and another CType formula on another column to get the text. That's 9 columns total to support 3 dropdown columns. Is there any way I can get rid of the extra 6 and just have one column for each dropdownlist, instead of 3 for each dropdownlist?
Thank you SO much, all of you. Your help is appreciated.
Jason
Jason
|
|
| |
|
| |
| Martin Garins |
You need to databind first.
The data is not there until you databind it so yes FindByValue will return Nothing.
myDropUser.DataSource =3D reader myDropUser.DataValueField =3D "user_id" myDropUser.DataTextField =3D "user_nm"
'// DATABIND myDropUser.DataBind()
'// THEN SET THE VALUE myDropUser.ClearSelection() Dim myListItem As ListItem =3D myDropUser.Items.FindByValue(CStr(CType(e.Item.Cells(4).Controls(0), TextBox).Text)) ' =3D "2" If Not (myListItem Is Nothing) Then myListItem.Selected =3D True End If
Martin Garins, MCSD Vice President - Technology e-Intersect Corp. http://www.e-intersect.com http://www.jppex.com
-----Original Message----- From: Jason Wisdom [mailto:Click here to reveal e-mail address]=20 Sent: Monday, June 10, 2002 1:18 PM To: aspngescalate Subject: [aspngescalate] RE: SV: Editable DropDownList in Datagrid - 3rd time asking
Hi all, thank you again Andre, Andre and Martin for your answers.
OK, it FINALLY seems I will be able to get this to work. But there has got to be a simpler way than how I'm doing it.
I tried each of your suggestions:
Martin G - Me.Items.FindByValue(Value) always seems to return Nothing. Even when in the Immediate Window I type in the same line with a value I know exists...I get Nothing back. Same when I code it in and place a watch on my ListItem. Your way seems like it would be the simplest - this is what I tried:
myDropUser.DataSource =3D reader myDropUser.DataValueField =3D "user_id" myDropUser.DataTextField =3D "user_nm" myDropUser.ClearSelection() Dim myListItem As ListItem =3D myDropUser.Items.FindByValue(CStr(CType(e.Item.Cells(4).Controls(0), TextBox).Text)) ' =3D "2" If Not (myListItem Is Nothing) Then myListItem.Selected =3D True End If myDropUser.DataBind()
Andre P. - When populating the DDLs, SelectedItem.Value by itself does not return anything, as nothing is selected. But it is turning out to be useful when I Save my changes, as that's how I'm reading the value. So that saves the next question I was going to ask.
Andre C. - I tried running these lines - ... myDropUser.DataBind() myDropUser.Items.Insert(0, "asdf") myDropUser.SelectedIndex =3D 0 myDropUser.SelectedItem.Value =3D = CInt(CType(e.Item.Cells(4).Controls(0), TextBox).Text) myDropUser.SelectedItem.Text =3D CStr(CType(e.Item.Cells(7).Controls(0), TextBox).Text) reader.Close()
This works! Great, thank you. But there are 2 things I'd like to smooth out: 1) The pre-selected item is duplicated and inserted before any other records. Is there any way to just select the desired item without creating a new dropdownlist record and going through all that? For example, if there are 7 Usernames, and I want the 5th with id=3D47 and name=3D"Jason", is there any way I can just say (go to the record with id=3D47)? That's what I'm really trying to do here. 2) In the .aspx file I'm working on presently, there are 3 columns with dropdownlists. Right now I have to do a whole CType formula on another column to get the id, and another CType formula on another column to get the text. That's 9 columns total to support 3 dropdown columns. Is there any way I can get rid of the extra 6 and just have one column for each dropdownlist, instead of 3 for each dropdownlist?
Thank you SO much, all of you. Your help is appreciated.
Jason
Jason
| [aspngescalate] member Click here to reveal e-mail address =3D YOUR ID=20 | http://www.asplists.com/asplists/aspngescalate.asp =3D JOIN/QUIT
|
|
| |
|
|
|
|
|