SV: RE: SV: Editable DropDownList in Datagrid - 3rd time asking
Messages   Related Types
This message was discovered on ASPFriends.com 'aspngescalate' list.


=?iso-8859-1?Q?Andr=E9_Colbi=F6rnsen?=
I usually do like this:

I use '0' As the default value for all tables that will be used for
filling dropdown boxes. If the dB value is '0' then I know that no
selection has been done so far.

'######################################################
'# Dropdown 'KLIENT NIV=C5' to be filled #=20
'######################################################=09

If Not intPrioID =3D 0 Then
Dim cmdSelect_Prio As New SqlCommand("Select prioritet From
klientprioritet_
Where prioritetID =3D " & intPrioID, conFamily)
strPrioritet =3D cmdSelect_Prio.ExecuteScalar()
Else
strPrioritet =3D "-- V=E4lj klientniv=E5 --"
End If

Conn.Open()
Dim strKlientNiva As String =3D cmdSelect.ExecuteScalar()
Conn.Close()
---------------------------------------------------------
Now I have the 'Text' from this particular table based on the 'value'
which is FK in the main table.
To get the DropDown filled and the right value and text selected, I do
like this:

'######################################################
'# Fill the Dropdown 'KLIENT NIV=C5' #=20
'######################################################

dtrReg =3D cmdSelect4.ExecuteReader()

DrpPriority.DataSource =3D dtrReg
DrpPriority.DataValueField =3D "prioritetID"
DrpPriority.DataTextField =3D "prioritet"
DrpPriority.DataBind()
DrpPriority.Items.Insert(0, strPrioritet)
DrpPriority.SelectedIndex =3D 0
DrpPriority.SelectedItem.Value =3D intPrioID
DrpPriority.SelectedItem.Text =3D strPrioritet
dtrReg.Close()
---------------------------------------------------------

Now I have the Dropdown prefilled with the selected choice. If the
person has not yet mad a choice, the 'value' is '0' and the 'text' is
"-- V=E4lj klientniv=E5 --".

Hth

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 8 juni 2002 00:41
Till: aspngescalate
=C4mne: [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

Reply to this message...
 
    
=?iso-8859-1?Q?Andr=E9_Colbi=F6rnsen?=
Well I tried to use the Aspalliance example myself, for something
similar in a project I'm working on right now and it worked just fine.
Here is my code:

=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
<asp:TemplateColumn HeaderText=3D"S=E4kerhetsniv=E5:"
HeaderStyle-BorderColor=3D"#000000" HeaderStyle-BorderStyle=3D"Solid"
HeaderStyle-BorderWidth=3D"1px" ItemStyle-BorderColor=3D"#000000"
ItemStyle-BorderStyle=3D"Solid" ItemStyle-BorderWidth=3D"1px" >
<ItemTemplate>
<asp:Table Runat=3Dserver Width=3D"100%" BorderColor=3D"Black"
BorderStyle=3D"Solid" BorderWidth=3D"1px" CellPadding=3D"1">
<asp:TableRow ID=3DtrSec Runat=3Dserver>
<asp:TableCell Runat=3Dserver HorizontalAlign=3D"Center"
Font-Size=3D"10px">
<%# FindSecurity(Container.DataItem( "sakerhetsid" )) %>
</asp:TableCell>
</asp:TableRow>
</asp:Table>
</ItemTemplate>
<EditItemTemplate>
<asp:DropdownList Id=3D"drpChange" CssClass=3D"drpDetalj" =
RunAt=3D"server"
/>
</EditItemTemplate>
</asp:TemplateColumn>

=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D Aspx.vb (Functions =
Findsecurity/FillSecurity, ItemDataBound
Sub, Update Sub =
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D

'--------------- Findsecurity
Public Function FindSecurity(ByVal intSecID As Integer) As String
Dim conFamily As SqlConnection =3D New SqlConnection(strConn)
Dim cmdSql As New SqlCommand("Select behorighet From sakerhetstbl where
sakerhetsid =3D " & intSecID, conFamily)
conFamily.Open()
Dim strSecurity As String =3D cmdSql.ExecuteScalar
conFamily.Close()
Return strSecurity
End Function

'--------------- Fillsecurity

Private Function FillSecurity() As DataView

Dim conFamily As SqlConnection =3D New SqlConnection(strConn)
Dim myAdapter As SqlDataAdapter

'------------- THE DATASET IS PUBLICLY DECLARED WITHIN THE CLASS
-------------------------
dstLosen =3D New DataSet()
myAdapter =3D New SqlDataAdapter("Select * from sakerhetstbl Order by
sakerhetsid", conFamily)
conFamily.Open()
myAdapter.Fill(dstLosen, "security")

Return dstLosen.Tables("security").DefaultView()

End Function

'--------------- ItemDataBound

Public Sub DataGrid_ItemDataBound(ByVal s As Object, ByVal e As
DataGridItemEventArgs) Handles myDataGrid.ItemDataBound
Dim itemType As ListItemType =3D e.Item.ItemType

If (itemType =3D ListItemType.Item Or itemType =3D
ListItemType.AlternatingItem) Then
Dim intId As Integer =3D e.Item.DataItem("sakerhetsid")
Dim btnDel As Button =3D CType(e.Item.FindControl("btnDel"), Button)
Dim trSec As TableRow =3D CType(e.Item.FindControl("trSec"), TableRow)

If intId =3D 1 Then
trSec.Attributes.Add("style", "background-color: #8fbc8f")
ElseIf intId =3D 2 Then
trSec.Attributes.Add("style", "background-color: #f0e68c")
ElseIf intId =3D 3 Then
trSec.Attributes.Add("style", "background-color: #ffa07a")
End If

btnDel.Attributes.Add("onclick", "return confirm('=C4r du s=E4ker p=E5 =
att
du vill nollst=E4lla login?');")

ElseIf itemType =3D ListItemType.EditItem Then
Dim intId As Integer =3D e.Item.DataItem("sakerhetsid")
Dim btnDel As Button =3D CType(e.Item.FindControl("btnDel"), Button)
Dim drpChange As DropDownList =3D =
CType(e.Item.FindControl("drpChange"),
DropDownList)
Dim myRowView As DataRowView =3D CType(e.Item.DataItem, DataRowView)
Dim mySecurity As String =3D myRowView("sakerhetsid").ToString()
drpChange.DataValueField =3D "sakerhetsid"
drpChange.DataTextField =3D "behorighet"
drpChange.DataSource =3D FillSecurity()
drpChange.DataBind()
drpChange.Items.FindByValue(mySecurity).Selected =3D True

Select Case intId
Case 1
drpChange.Attributes.Add("style", "background-color: #8fbc8f")
Case 2
drpChange.Attributes.Add("style", "background-color: #f0e68c")
Case 3
drpChange.Attributes.Add("style", "background-color: #ffa07a")
End Select
btnDel.Attributes.Add("onclick", "return confirm('=C4r du s=E4ker p=E5 =
att
du vill nollst=E4lla login?');")

End If
End Sub

'--------------- Update

Sub DataGrid_UpdateCommand(ByVal sender As Object, ByVal e As
DataGridCommandEventArgs) Handles myDataGrid.UpdateCommand
Dim conFamily As SqlConnection =3D New SqlConnection(strConn)
Dim txtAnvId As TextBox =3D CType(e.Item.FindControl("txtAnvId"),
TextBox)
Dim txtPwd As TextBox =3D CType(e.Item.FindControl("txtPwd"), TextBox)
'----------- HERE IS THE DDL WHICH IS OF INTEREST TO YOU
--------------------------
Dim drpChange As DropDownList =3D =
CType(e.Item.FindControl("drpChange"),
DropDownList)
Dim intID As Integer
Dim strAnvid As String =3D Trim(Replace(txtAnvId.Text, "'", ""))
Dim strPwd As String =3D Trim(Replace(txtPwd.Text, "'", ""))
Dim intSec As Integer =3D drpChange.SelectedItem.Value
Dim strSql As String

intID =3D myDataGrid.DataKeys(e.Item.ItemIndex)

strSql =3D "Update employeetbl Set
anvid=3D@strAnvid,pwd=3D@strPwd,sakerhetsid=3D@intSec Where =
empid=3D@intID"

Dim cmdSql As New SqlCommand(strSql, conFamily)

If strAnvid =3D "" Then
cmdSql.Parameters.Add("@strAnvid", System.DBNull.Value)
Else
cmdSql.Parameters.Add("@strAnvid", strAnvid)
End If

If strPwd =3D "" Then
cmdSql.Parameters.Add("@strPwd", System.DBNull.Value)
Else
cmdSql.Parameters.Add("@strPwd", strPwd)
End If
=20
cmdSql.Parameters.Add("@intID", intID)
cmdSql.Parameters.Add("@intSec", intSec)

conFamily.Open()
cmdSql.ExecuteNonQuery()
conFamily.Close()

myDataGrid.EditItemIndex =3D -1

TableRow4.Visible =3D True
lblOK.Text =3D "<strong><font color=3D'Green'>** DATABASEN =C4R =
UPPDATERAD
**</font></strong>"

BindGrid()
End Sub

=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
This should take care of exactly what you are after. Hope you can use
it.

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 10 juni 2002 20:18
Till: aspngescalate
=C4mne: [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

Reply to this message...
 
    
Jason Wisdom
OK, it works. THANK YOU guys, very much.

The winning combination was...

Dim myDropUser As DropDownList =3D CType(e.Item.FindControl("ddlUser"),
DropDownList)
Dim reader As SqlDataReader
Dim strSQL As String =3D "SELECT user_id, user_nm FROM tblXUsers"

FillDataReader(reader, strSQL) ' sub in another module
myDropUser.DataSource =3D reader
myDropUser.DataValueField =3D "user_id"
myDropUser.DataTextField =3D "user_nm"
myDropUser.DataBind()
myDropUser.Items.FindByValue(CStr(e.Item.Cells(4).Text)).Selected =3D =
True
reader.Close()

So the key was "mydropuser.items.findbyvalue("2").selected =3D true".

Ahhhh..... I think I'm going to have a strong beer for lunch. =20
Thanks again.

Jason

Reply to this message...
 
    
Andy Smith
just so you know...

for some time i've been working on a better solution to this, and the =
result is a mostly done LookupColumn for the datagrid. I'm not 100% =
happy with it yet... but as soon as I am, I plan on unleashing it upon =
the world for free with source.

I don't know when I'll actually get around to finishing it... maybe a =
little incentive from somebody? hint hint

__
Andy Smith
Chief Code Monkey

[Original message clipped]

Reply to this message...
 
 
System.ComponentModel.Container
System.Data.DataRowView
System.Data.DataSet
System.Data.DataView
System.Data.SqlClient.SqlCommand
System.Data.SqlClient.SqlConnection
System.Data.SqlClient.SqlDataAdapter
System.Data.SqlClient.SqlDataReader
System.DBNull
System.Web.UI.MobileControls.TextBox
System.Web.UI.WebControls.BorderStyle
System.Web.UI.WebControls.DataGrid
System.Web.UI.WebControls.DataGridCommandEventArgs
System.Web.UI.WebControls.DataGridItemEventArgs
System.Web.UI.WebControls.DropDownList
System.Web.UI.WebControls.HorizontalAlign
System.Web.UI.WebControls.ListItem
System.Web.UI.WebControls.ListItemType
System.Web.UI.WebControls.TableCell
System.Web.UI.WebControls.TableRow
System.Web.UI.WebControls.TemplateColumn
System.Web.UI.WebControls.TextBox
System.Windows.Forms.BorderStyle
System.Windows.Forms.DataGrid
System.Windows.Forms.TextBox




Ad
MBR BootFX
Best-of-breed application framework for .NET projects, developed by Matthew Baxter-Reynolds and MBR IT
 
 Copyright © Matthew Baxter-Reynolds 2001-2008. '.NET 247 Software Development Services' is a trading style of MBR IT Solutions Ltd.
Contact Us - Terms of Use - Privacy Policy - www.dotnet247.com