﻿<?xml version="1.0" encoding="utf-8"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:media="http://search.yahoo.com/mrss/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0"><channel><title>Intersoft Community - WebGrid Enterprise - How do I Insert a ListItem into a DropDownList?</title><link>http://www.intersoftsolutions.com/Community/WebGrid/How-do-I-Insert-a-ListItem-into-a-DropDownList/</link><description /><generator>http://www.intersoftsolutions.com</generator><language>en</language><copyright>Copyright 2002 - 2015 Intersoft Solutions Corp. All rights reserved.</copyright><ttl>60</ttl><item><title>How do I Insert a ListItem into a DropDownList?</title><link>http://www.intersoftsolutions.com/Community/WebGrid/How-do-I-Insert-a-ListItem-into-a-DropDownList/</link><pubDate>Sun, 14 Feb 2010 22:07:31 GMT</pubDate><dc:creator>Glayaar</dc:creator><description>&lt;p&gt;Here is the updated snippet for OPTION element:&lt;/p&gt;&lt;pre&gt;function _WebGrid_OnEnterEditMode(controlId, tblName, editObject) {   &lt;br /&gt;    //The workaround provided for the user for this issue&lt;br /&gt;    &lt;br /&gt;    var _WebGrid = ISGetObject(controlId);&lt;br /&gt;&lt;br /&gt;    var cellObj = editObject.ToCellObject();&lt;br /&gt;&lt;br /&gt;    if (cellObj.Name == "Priority_WebGridColumn") {&lt;br /&gt;        &lt;br /&gt;        var options = editObject.element.getElementsByTagName('option');&lt;br /&gt;        if (options[0].text !=  '--- PLEASE SELECT ---') {&lt;br /&gt;            var newOpt = document.createElement('option');&lt;br /&gt;            newOpt.setAttribute('value', '0');&lt;br /&gt;            newOpt.innerHTML = '--- PLEASE SELECT ---';&lt;br /&gt;            editObject.element.insertBefore(newOpt, options[0]);&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    return true;&lt;br /&gt;}&lt;/pre&gt;&lt;p&gt;The basic idea of the function is the same, however this snippet will insert a OPTION HTML element instead of OPTGROUP.&lt;/p&gt;
&lt;p&gt;Regarding the issue in the other &lt;a href="../DropDownList-Default-Value-Not-Selected-in-Edit-Mode-when-using-IE/" target="_blank"&gt;thread&lt;/a&gt;, I will reply my response in that thread in order to kept the discussion in this thread on topic. &lt;br /&gt;&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p&gt; &lt;br /&gt;&lt;/p&gt;</description></item><item><title>How do I Insert a ListItem into a DropDownList?</title><link>http://www.intersoftsolutions.com/Community/WebGrid/How-do-I-Insert-a-ListItem-into-a-DropDownList/</link><pubDate>Fri, 12 Feb 2010 01:36:48 GMT</pubDate><dc:creator>DJBadin</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;The example you gave creates an OPTGROUP element.&lt;/p&gt;
&lt;p&gt;It does not add and OPTION to the top of the OPTION List like my Server Side Code does for RefurbPriority_DropDownList.&lt;br /&gt;&lt;br /&gt;With your code, I am not able to set the Selected Index using your workaround for IE you gave me in &lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.intersoftpt.com/Community/WebGrid/DropDownList-Default-Value-Not-Selected-in-Edit-Mode-when-using-IE/"&gt;http://www.intersoftpt.com/Community/WebGrid/DropDownList-Default-Value-Not-Selected-in-Edit-Mode-when-using-IE/&lt;/a&gt;&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;How do I add an OPTION to the top of the OPTION List like my Server Side Code does for RefurbPriority_DropDownList?&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;Doug&lt;/p&gt;</description></item><item><title>How do I Insert a ListItem into a DropDownList?</title><link>http://www.intersoftsolutions.com/Community/WebGrid/How-do-I-Insert-a-ListItem-into-a-DropDownList/</link><pubDate>Mon, 08 Feb 2010 22:10:24 GMT</pubDate><dc:creator>Glayaar</dc:creator><description>&lt;p&gt;You could try inserting the new element during OnEnterEditMode WebGrid client side event handler. Here is the snippet that I used to achieve your desired result:&lt;br /&gt;&lt;/p&gt;&lt;pre&gt;function _WebGrid_OnEnterEditMode(controlId, tblName, editObject) {&lt;br /&gt;    var _WebGrid = ISGetObject(controlId);&lt;br /&gt;&lt;br /&gt;    var cellObj = editObject.ToCellObject();&lt;br /&gt;&lt;br /&gt;    if (cellObj.Name == "Priority_WebGridColumn") {&lt;br /&gt;&lt;br /&gt;        if (editObject.element.getElementsByTagName('optgroup').length == 0) {&lt;br /&gt;            var newGrp = document.createElement('optgroup');&lt;br /&gt;            newGrp.setAttribute('label', '--- PLEASE SELECT ---');&lt;br /&gt;&lt;br /&gt;            var length = editObject.element.length;&lt;br /&gt;            for (var i = 0; i &amp;lt; length; i&amp;#43;&amp;#43;) {&lt;br /&gt;                newGrp.appendChild(editObject.element.options[0]);&lt;br /&gt;            }&lt;br /&gt;&lt;br /&gt;            editObject.element.appendChild(newGrp);&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    return true;&lt;br /&gt;}&lt;/pre&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;&lt;/p&gt;</description></item><item><title>How do I Insert a ListItem into a DropDownList?</title><link>http://www.intersoftsolutions.com/Community/WebGrid/How-do-I-Insert-a-ListItem-into-a-DropDownList/</link><pubDate>Mon, 08 Feb 2010 18:06:32 GMT</pubDate><dc:creator>DJBadin</dc:creator><description>&lt;p&gt;How do I Insert a ListItem into a DropDownList for a WebGridColum of EditType DropDownList.&lt;/p&gt;
&lt;p&gt;With an asp:DropDownList I can use it's OnPreRender Event to Insert "--- PLEASE SELECT ---" at the top of List retrieved from the Database as in the code below.  I have not been able to figure out how to get a reference to the generated DropDownList Server Side to do this. &lt;/p&gt;&lt;pre&gt;&amp;lt;%@ Page Language="C#" AutoEventWireup="true" %&amp;gt;

&amp;lt;%@ Import Namespace="System.Data" %&amp;gt;


&amp;lt;%@ Register assembly="ISNet.WebUI.WebGrid" namespace="ISNet.WebUI.WebGrid" tagprefix="ISWebGrid" %&amp;gt;

&amp;lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&amp;gt;

&amp;lt;html xmlns="http://www.w3.org/1999/xhtml"&amp;gt;

&amp;lt;head runat="server"&amp;gt;
    &amp;lt;title&amp;gt;&amp;lt;/title&amp;gt;
    
	&amp;lt;script runat="server"&amp;gt;
		
		protected void _WebGrid_InitializeLayout(object sender, LayoutEventArgs e)
		{
			ISNet.WebUI.WebGrid.WebValueList Priority_WebValueList = _WebGrid.GetTableByName("").Columns.GetNamedItem("Priority_WebGridColumn").ValueList;

			SortedList Priority_SortedList = new SortedList();

			Priority_SortedList.Add("ASSESS - 1", "1");
			Priority_SortedList.Add("ASSESS - 2", "2");
			Priority_SortedList.Add("ASSESS - 3", "3");
			Priority_SortedList.Add("DISPOSE", "D");
			Priority_SortedList.Add("UNDECIDED", "");

			Priority_WebValueList.DataSource = Priority_SortedList;
			Priority_WebValueList.DataTextField = "Key";
			Priority_WebValueList.DataValueField = "Value";

			RefurbPriority_DropDownList.DataSource = Priority_SortedList;
			RefurbPriority_DropDownList.DataTextField = "Key";
			RefurbPriority_DropDownList.DataValueField = "Value";

			RefurbPriority_DropDownList.SelectedValue = "";

			RefurbPriority_DropDownList.DataBind();
		}


		protected void Company_DropDownList_PreRender(object sender, EventArgs e)
		{
			DropDownList _DropDownList = (DropDownList) sender;
			_DropDownList.Items.Insert(0, "--- PLEASE SELECT ---");
		}
				
	&amp;lt;/script&amp;gt;

&amp;lt;/head&amp;gt;

&amp;lt;body&amp;gt;
    &amp;lt;form id="form1" runat="server"&amp;gt;
    &amp;lt;div&amp;gt;

	&amp;lt;table&amp;gt;
		&amp;lt;tr&amp;gt;
			&amp;lt;td&amp;gt;PRIORITY&amp;lt;/td&amp;gt;
			&amp;lt;td&amp;gt;COMPANY&amp;lt;/td&amp;gt;
		&amp;lt;/tr&amp;gt;
		&amp;lt;tr&amp;gt;
			&amp;lt;td&amp;gt;
				&amp;lt;ASP:DROPDOWNLIST 
					ID="RefurbPriority_DropDownList" 
					runat="server"
				&amp;gt;
				&amp;lt;/ASP:DROPDOWNLIST&amp;gt;
			&amp;lt;/td&amp;gt;
			&amp;lt;td&amp;gt;
				&amp;lt;ASP:DROPDOWNLIST 
					ID="Company_DropDownList" 
					runat="server" 
					DataValueField="CustomerID"
					DataTextField="CompanyName"
					DataSourceID="Company_SqlDataSource"
					onPreRender="Company_DropDownList_PreRender"
				&amp;gt;
				&amp;lt;/ASP:DROPDOWNLIST&amp;gt;
				
			&amp;lt;/td&amp;gt;
		&amp;lt;/tr&amp;gt;
		&amp;lt;tr&amp;gt;
			&amp;lt;td colspan="2"&amp;gt;
				&amp;lt;ISWebGrid:WebGrid 
					ID="_WebGrid"
					runat="server"
					DataSourceID="Orders_SqlDataSource"
					Height="250px"
					UseDefaultStyle="True"
					DefaultStyleMode="Win7"
					OnInitializeLayout="_WebGrid_InitializeLayout"
				&amp;gt;
					&amp;lt;LayoutSettings
						AllowEdit="Yes"
						AllowSorting="Yes"
						AllowBatchUpdate="true"
					&amp;gt;
						&amp;lt;BatchUpdateSettings
							AllowReviewChanges="true"
							AutomaticObjectUpdate="false"
						/&amp;gt;
					&amp;lt;/LayoutSettings&amp;gt;
					&amp;lt;RootTable
						DataKeyField="OrderID"
					&amp;gt;
						&amp;lt;Columns&amp;gt;
							&amp;lt;ISWebGrid:WebGridColumn
								Name="Priority_WebGridColumn"
								Bound="True"
								DataMember="REFURB_PRIORITY"
								EditType="DropdownList"
								Caption="PRIORITY"
								Width="100px"
								NullText=""
								DefaultValue=""
								InputRequired="true"
								InputRequiredErrorText="Priority Needed"
							&amp;gt;
							&amp;lt;/ISWebGrid:WebGridColumn&amp;gt;
							&amp;lt;ISWebGrid:WebGridColumn
								Name="Company_WebGridColumn"
								Bound="True"
								EditType="DropdownList"
								Caption="Company"
								Width="100px"
								InputRequired="false"
							&amp;gt;
								&amp;lt;ValueList
									DataSourceID="Company_SqlDataSource"
									DataTextField="CompanyName"
									DataValueField="CustomerID"
								&amp;gt;
								&amp;lt;/ValueList&amp;gt;
							&amp;lt;/ISWebGrid:WebGridColumn&amp;gt;
							&amp;lt;ISWebGrid:WebGridColumn
								Caption="Order ID"
								EditType="NoEdit"
								DataMember="OrderID"
								Name="OrderID_WebGridColumn"
								Width="100px"
							&amp;gt;
								&amp;lt;CellStyle ForeColor="Black"/&amp;gt;
							&amp;lt;/ISWebGrid:WebGridColumn&amp;gt;

						&amp;lt;/Columns&amp;gt;
					&amp;lt;/RootTable&amp;gt;
				&amp;lt;/ISWebGrid:WebGrid&amp;gt;
				&amp;lt;/td&amp;gt;
		&amp;lt;/tr&amp;gt;
	&amp;lt;/table&amp;gt;
	
	&amp;lt;asp:SqlDataSource
		ID="Company_SqlDataSource"
		runat="server"
		ConnectionString="&amp;lt;%$ ConnectionStrings:NorthwindConnectionString2005 %&amp;gt;"
		SelectCommand="SELECT [CustomerID], [CompanyName] FROM [Customers] ORDER BY [CustomerID]"
	&amp;gt;&amp;lt;/asp:SqlDataSource&amp;gt;

	&amp;lt;asp:SqlDataSource
		ID="Orders_SqlDataSource"
		runat="server"
		ConnectionString="&amp;lt;%$ ConnectionStrings:NorthwindConnectionString2005 %&amp;gt;"
		SelectCommand="SELECT TOP 5 [OrderID], [CustomerID], '' AS REFURB_PRIORITY, '' AS GRAPHICS_NEW FROM [Orders] ORDER BY [OrderID]"
	&amp;gt;&amp;lt;/asp:SqlDataSource&amp;gt;

    &amp;lt;/div&amp;gt;
    &amp;lt;/form&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/pre&gt;
</description></item></channel></rss>