Search:
Namespaces
Discussions
.NET v1.1
Feedback
Editable DropDownList in Datagrid - 3rd time asking
Messages
Related Types
This message was discovered on
ASPFriends.com 'aspngescalate' list
.
Jason Wisdom
-- 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....=20
Any ideas? Thank you if you can help.
Jason
Reply to this message...
Martin Garins
You have something like this in your asp:datagrid
<asp:templatecolumn headertext=3D"Status">
<headerstyle width=3D"75px"></headerstyle>
<itemtemplate>
<asp:label id=3D"lblStatus2" runat=3D"server" text=3D'<%#
String
.format("{0}",
Container
.DataItem("STATUS_TEXT")) %>'>
</asp:label>
</itemtemplate>
<edititemtemplate>
<asp:DropDownList id=3D"cmbStatus" runat=3D"server"></asp:DropDownList>
</edititemtemplate>
</asp:templatecolumn>
In the ItemCreated Event=20
You need to have code similar to this
Dim itemtype As
ListItemType
=3D CType(e.Item.ItemType,
ListItemType)
If itemtype =3D
ListItemType
.EditItem Then
'// cmbStatus is the id of control in the edititemtemplate
Dim ctlStatus As
DropDownList
=3D
CType(e.Item.FindControl("cmbStatus"),
DropDownList
)
If Not (ctlStatus Is Nothing) Then
' Run code to fill your Dropdown
End If
End If
Then in the ItemDatabound Event you need code similar to this
Dim itemtype As
ListItemType
=3D CType(e.Item.ItemType,
ListItemType)
If itemtype =3D
ListItemType
.EditItem Then
Dim values As
DataRowView
=3D CType(e.Item.DataItem,
DataRowView)
Dim ctlStatus As
DropDownList
=3D
CType(e.Item.FindControl("cmbStatus"),
DropDownList
)
If Not (ctlStatus Is Nothing) Then
Call
ctlStatus.SelectItemByValue(values("RELATION_STATUS"))
End If
End If
Then in your save funtion
'// the variable i is a row number in your grid
Dim ctlStatus as
DropDownList
For I =3D 0 to Me.idofdatagrid.items.count -1
ctlStatus =3D CType(Me.idofdatagrid.Items(i).FindControl("cmbStatus"),
DropDownList
)
If not(ctlStatus is nothing) then
'// Use Value
End if
Next
I hope that 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: Thursday, June 06, 2002 12:33 PM
To: aspngescalate
Subject: [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
Reply to this message...
System.ComponentModel.Container
System.Data.DataRowView
System.String
System.Web.UI.WebControls.DropDownList
System.Web.UI.WebControls.ListItemType
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