Populating with code a DropDownList used as an editing control in a Datagrid

I want to use a dropdownlist in an editing DataGrid, but want to specify in my code what the listed values should be. The dropdownlist is to show the values "High", "Normal", and "Low".

Can't figure out how to do this. Can't stuff in values in the edititemtemplate declaration of the control, and can't add items in my code upstream as the control doesn't yet exist. I was hoping to be able to do this rather than have to create another table in my database with just these 3 values create a dataset for that table and bind to that. Seems like that would be overkill.
How does one do this?
Thx
Stephen
0
hondaman900
10/25/2003 11:43:06 PM
asp.net.presentation-controls 72751 articles. 3 followers. Follow

3 Replies
736 Views

Similar Articles

[PageSpeed] 41

I have done this by using the dropdoenlist's OnInit event as follows:


<asp:DropDownList id="ddlPrority" runat="server" OnInit="ddlPriority_OnInit" />

Public Sub ddlPriority_OnInit(ByVal Sender As Object, ByVal E As EventArgs)
Dim ddl As DropDownList = CType(Sender, DropDownList)
ddl.Items.Add("High")
ddl.Items.Add("Normal")
ddl.Items.Add("Low")
End Sub

You can then use the OnPreRender event to select a particular value if you need to.
Hope this helps,
Paul
0
plhester
10/26/2003 3:20:36 AM
This works great, but brings up a related problem. When collecting the selected item for my SQL UPDATE statement I thought the following would work, but it doesn't


CType(e.Item.FindControl("ddlPriority"), DropDownList).SelectedItem.text

I get a "BC30648: String constants must end with a double quote" error. My SQL statement has a correct number of double quotes, so something in the above line is messing this up.
Also, setting the selecteditem.text to the filed value in the database doesn't work as I thought it should. I have

<edititemtemplate>
<asp:DropDownList id="ddlPrority" runat="server" OnInit="ddlPriority_OnInit" width="70" selecteditem.text='<%# DataBinder.Eval(Container, "DataItem.priority") %>' />
</edititemtemplate>

gives an "The server tag is not well formed" error. removing the "selecteditem" reference gets past this, but leaves an invalid 'text property reference for the DDL.
Any suggestions?
Thx
Stephen
0
hondaman900
10/26/2003 10:09:09 PM
Actually, I found the issue in my SQL statement formation (wasn't the selecteditem.text). However, my attempt to have the editing dropdownlist show the database value when generated in the DataGrid is still getting the better of me.

Your thoughts?
Stephen
0
hondaman900
10/26/2003 10:23:19 PM
Reply:

Web resources about - Populating with code a DropDownList used as an editing control in a Datagrid - asp.net.presentation-controls

Tag Synonyms - Stack Overflow
Q&A for professional and enthusiast programmers

Accidental entities - what about the UI?
This post is a follow-up to my previous blog post " Accidental entities - you don't need that identity ". In that post, we followed a consultant ...

Flash Builder Plug-in for SAP Netweaver Gateway - Adobe Labs
Search Navigation Labs Home Wiki Home Technologies Alchemy Blueprint Camera Profiles and DNG Profile Editor Cirrus ColdFusion 10 DNG Codec Fireworks ...

Air Astana - Join Now
Thank you for considering membership of Nomad Club – Kazakhstan’s first Frequent Flyer Program. You could soon be on your way to earning free ...

Languages -> C# Articles, Tutorials, Examples: ASP Alliance
.NET,ASP,ASP.NET,SQL,XML,HTML,ADO,ADO.NET,JavaScript,JScript,CSharp,VBScript and VB tutorials from AspAlliance.

Blog - Avisra
Avisra Web Development Home Blog Services Contact The Blog Latest Module Builder: How can we make it better? Sitefinity by Chris on July 2, 2013 ...

Online Booking Tool Support
This Online Booking Tool Support page might help you as you navigate through the process of booking travel through your OBT provided by CWT. ...

@Html and beyond
... ); } return string .Format( “{0}{1}” , me.Member.Name, id); } The Html building methods are quite simple. Building a dropdownlist for a ...

Top Ranked Articles
Top Ranked Articles - Free source code and tutorials for Software developers and Architects.; Updated: 23 Feb 2013

Unit Testing DateTime.Now Without Isolation
public virtual void SeedWithYearsSince(DropDownList list, int year){ for (int index = year; index

Resources last updated: 12/8/2015 12:34:15 PM