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?
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)
You can then use the OnPreRender event to select a particular value if you need to.
Hope this helps,
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
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
<asp:DropDownList id="ddlPrority" runat="server" OnInit="ddlPriority_OnInit" width="70" selecteditem.text='<%# DataBinder.Eval(Container, "DataItem.priority") %>' />
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.
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.