iSeller Commerce
iSeller POS Retail
iSeller POS F&B
iSeller POS Express
Crosslight
WebUI
ClientUI
What's New
Download Trial
Web Solution
Mobile Solution
Enterprise Solution
Custom Development
Blog
Community
Latest Development Blogs
ForumPostTopic
Browse By Tag
The DropDownList Default Value is Not Selected in Edit Mode when using IE.
With the code below:
<%@ Page Language="C#" AutoEventWireup="true" %> <%@ Import Namespace="System.Data" %> <%@ Register assembly="ISNet.WebUI.WebGrid" namespace="ISNet.WebUI.WebGrid" tagprefix="ISWebGrid" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <script runat="server"> 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 ---"); } </script> </head> <body> <form id="form1" runat="server"> <div> <table> <tr> <td>PRIORITY</td> <td>COMPANY</td> </tr> <tr> <td> <ASP:DROPDOWNLIST ID="RefurbPriority_DropDownList" runat="server" > </ASP:DROPDOWNLIST> </td> <td> <ASP:DROPDOWNLIST ID="Company_DropDownList" runat="server" DataValueField="CustomerID" DataTextField="CompanyName" DataSourceID="Company_SqlDataSource" onPreRender="Company_DropDownList_PreRender" > </ASP:DROPDOWNLIST> </td> </tr> <tr> <td colspan="2"> <ISWebGrid:WebGrid ID="_WebGrid" runat="server" DataSourceID="Orders_SqlDataSource" Height="250px" UseDefaultStyle="True" DefaultStyleMode="Win7" OnInitializeLayout="_WebGrid_InitializeLayout" > <LayoutSettings AllowEdit="Yes" AllowSorting="Yes" AllowBatchUpdate="true" > <BatchUpdateSettings AllowReviewChanges="true" AutomaticObjectUpdate="false" /> </LayoutSettings> <RootTable DataKeyField="OrderID" > <Columns> <ISWebGrid:WebGridColumn Name="Priority_WebGridColumn" Bound="True" DataMember="REFURB_PRIORITY" EditType="DropdownList" Caption="PRIORITY" Width="100px" NullText="" DefaultValue="" InputRequired="true" InputRequiredErrorText="Priority Needed" > </ISWebGrid:WebGridColumn> <ISWebGrid:WebGridColumn Name="Company_WebGridColumn" Bound="True" EditType="DropdownList" Caption="Company" Width="100px" InputRequired="false" > <ValueList DataSourceID="Company_SqlDataSource" DataTextField="CompanyName" DataValueField="CustomerID" > </ValueList> <CellStyle BackColor="Yellow"/> </ISWebGrid:WebGridColumn> <ISWebGrid:WebGridColumn Caption="Order ID" EditType="NoEdit" DataMember="OrderID" Name="OrderID_WebGridColumn" Width="100px" > <CellStyle ForeColor="Black"/> </ISWebGrid:WebGridColumn> </Columns> </RootTable> </ISWebGrid:WebGrid> </td> </tr> </table> <asp:SqlDataSource ID="Company_SqlDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString2005 %>" SelectCommand="SELECT [CustomerID], [CompanyName] FROM [Customers] ORDER BY [CustomerID]" ></asp:SqlDataSource> <asp:SqlDataSource ID="Orders_SqlDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString2005 %>" SelectCommand="SELECT TOP 5 [OrderID], [CustomerID], '' AS REFURB_PRIORITY, '' AS GRAPHICS_NEW FROM [Orders] ORDER BY [OrderID]" ></asp:SqlDataSource> </div> </form> </body> </html>
The OPTGROUP is used to grouped options in the SELECT HTML element and by default is not selectable. You could read more about OPTGROUP in this page
Thank you for the page sample. I have replicate the issue in my environment. The behavior in IE could be corrected using this workaround:
function _WebGrid_OnEnterEditMode(controlId, tblName, editObject) { var _WebGrid = ISGetObject(controlId); var cellObj = editObject.ToCellObject(); if (cellObj.Name == "Priority_WebGridColumn") { var selIndex = editObject.element.length - 1; for (var i = 0; i < editObject.element.length; i++) { if (editObject.element.options[i].value == cellObj.Value) { selIndex = i; break; } } editObject.element.selectedIndex = selIndex; } return true;}
I have also inform the issue to our developer so it could be fixed in the future WebGrid release.
<ISWebGrid:WebGrid ID="_WebGrid" runat="server"> <LayoutSettings> <ClientSideEvents OnEnterEditMode="_WebGrid_OnEnterEditMode" /> </LayoutSettings> ...</ISWebGrid:WebGrid>
Hi,
The problem has nothing to do with wiring up the event.
The code you initially provided in the other thread used a OPTGROUP and does not work with this code.The code you just provided in the other thread uses a OPTION and does work with this code.If you re-test this code with the OPTGROUP code you will find it does not work.
Doug
Attached is the sample I used to test the OPTGROUP and DroDownList item select upon entering WebGrid edit mode.
My test show the code will run without any issue. The Undecided option will be initially selected upon entering the cell for the first time.
The problem is the '--- PLEASE SELECT ---', the OPTGROUP, can not be selected.
or
Choose this if you're already a member of Intersoft Community Forum. You can link your OpenID account to your existing Intersoft Social ID.
Choose this if you don't have an Intersoft account yet. Your authenticated OpenID will be automatically linked to your new Intersoft account.
Enter your Wordpress Blogname