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
I have a WebGrid with a WebGridColumn of EditType="WebComboNET". It's WebCombo is unbound and has MultipleSelectionSettings is Enabled.
How do I set multiple values or even single values to show up in the DropDown?
I tried using the Server Side Webgrid IntializeRow Event to set the WebGridCell Text and Value, however when the DropDown is displayed, nothing is checked. With MultipleSelectionSettings not Enabled, the DropDown selects the value.
I have attached a sample using the Northwind Database. A DataSet for the Tables Shippers and Region would need to be created.
I have the latest versions of the Intersoft Controls.
I am using Visual Studio 2012
Thanks,
Doug
Hi,
Thanks, you anticipated my next question. When I was doing testing, the example UsingWebComboNETwithMultipleSelection you provided, worked and mine did not. I had simplified mine to mimic UsingWebComboNETwithMultipleSelection and mine still had a problem. I was beginning to think it was database related.
My actual application uses varchar and it works okay when I just put in the BoundMode="ForceUnbound". My sample was just simplified and modified to use the Northwind.mdf so you could reproduce the problem. As chance would have it I picked a column of datatype nchar which ends up padding the Text with spaces as you explained.
Hello,Thank you for your question and the sample.In order to you set value in multiple selections, you should use SetMultipleValues method.With SetMultipleValues method, you could set more than one value.I made a simple WebCombo sample using multiple selection and SetMultipleValues method.Please kindly have review on the sample to know see the result.You could see more information about SetMultipleValues method in WebCombo documentation.Thank you very much.Regards,Hans.
Thanks for the try, I already saw that but your example is for a Standalone WebCombo and does Not work for my example with a WebCombo in each WebGridRow.
How do I make it work for my sample?
Each WebGridRow effectively has different values.
I simplified my sample, but in real life, each of these Values represents a individual record in a Database Table. When the WebGridRow is updated I will separate these Values from the WebCombo and update Table accordingly using a Stored Procedure. Likewise when the WebGrid is Loaded, I will take these multiple records Values and concatinate them for the WebGrid Combo. I have to go this route because there a other relationships on the Table that have to be satisfied, hence the Store Procedure.
Which WebGrid Server Side Event exposes each WebCombo?
Like I referenced in the first post, in the IntializeRow Event I can only get to the WebGridCell and even then it only populates the DropDown display when MultipleSelectionSettings is Not Enabled. I need MultipleSelectionSettings Enabled.
Or, do I have to do it client side when maybe the DropDown is displayed.
Please try it with my sample.
Remember this is in a WebGridRow.
Apparantly the Values and Text are loading but the boxes are not checked.
I can load them Server Side in WebGrid OnIntializeRow:
protected void _WebGrid_InitializeRow(object sender, RowEventArgs e) { if (e.Row.Table.Name == "Shippers") { if (e.Row.Type == RowType.Record) { WebGridCellCollection _WebGridCellCollection = e.Row.Cells; DataRowView _DataRow = e.Row.DataRow as DataRowView; Int32 ShipperID_Int32 = Convert.ToInt32(_DataRow["ShipperID"].ToString()); String CompanyName_String = _DataRow["CompanyName"].ToString(); WebGridCell Regions_WebGridCell = (WebGridCell)e.Row.Cells.GetNamedItem("Regions_WebGridColumn"); switch (ShipperID_Int32) { case 1: Regions_WebGridCell.Text = "Eastern"; Regions_WebGridCell.Value = "1"; break; case 2: Regions_WebGridCell.Text = "Eastern; Western"; //"Western"; //"Eastern; Western" Regions_WebGridCell.Value = "1;2"; //"2"; // "1;2" break; case 3: Regions_WebGridCell.Text = "Northern"; Regions_WebGridCell.Value = "3"; break; } } } }
This is confirmed client side with WebCombo OnShowDropDown:
<script language="javascript" type="text/javascript"> function Regions_WebCombo_OnShowDropDown(controlId) { GetValues(); } function GetValues() { var combo = ISGetObject("Regions_WebCombo"); var values = combo.GetMultipleValues(); if (values == null || values.length == 0) { alert("There are no values in Regions_WebCombo!"); } else { var s = ""; for (var i = 0; i < values.length; i++) { var valueItem = values[i]; s += "Text='" + valueItem.Text + "'; Value='" + valueItem.Value + "'" + " "; } alert("Values entered in Regions_WebCombo are: " + s); } } </script>
I can check them in the DropDown, but why is it not checking them depending on the Values and Text?
See attached graphics.
I tried the WebCombo RefreshValueItems Method Client Side but that did not help.
Hello,Thank you for your reply.I am really sorry, but I can’t run sample on my end, due to I don’t have your app_code file.Would you mind to provide the sample that I can run the sample properly?So I can help you to investigate this issue further more.Thank you very much.Regards,Hans.
I did not include my DataSets for the App_Code directory because I did not know the Web.config connectionString you would be using to connect to the Northwind Database.
I did not realize when I said in my first posting "A DataSet for the Tables Shippers and Region would need to be created." that you would not know how to create one or that your colleagues did not know how to either or would not help you. You should have let me know in your first reply.
I assumed someone at Intersoft would know how to create a DataSet because they are used in the Intersoft ASP.NET Samples Projects.
Since the Regions table is in the SQL Northwind.mdf and not in Northwind.mdb you will need to use the SQL Database. This can be identified by it's file extension of .mdf, not .mdb.
For instance, the Web.config in the WebGrid "C# Samples (Visual Studio 2010 Solution)" has the following SqlNorthwindConnectionString connectionString.
<add name="SqlNorthwindConnectionString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Northwind.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True" providerName="System.Data.SqlClient"/>
Like the WebGrid "C# Samples (Visual Studio 2010 Solution)" you will have to have your Northwind.mdf and Northwind_log.ldf files in the App_Data Directory.
Next you need to create the DataSets in the App_Code directory.
Inspecting each ISDataSource.SchemaName you will find the names of the DataSet to use.
<ISDataSource:ISDataSource ID="Shippers_ISDataSource" runat="server" SchemaName="dsNorthwindShippers"
<ISDataSource:ISDataSource ID="Region_ISDataSource" runat="server" SchemaName="dsNorthwindRegion"
For my sample you need to create the following DataSets:
- dsNorthwindShippers- dsNorthwindRegion
If you have problems following my instructions on how to create a DataSet there are many resources typing “visual studio create dataset” into Google which returns links to MSDN How Tos, YouTube Videos and other content.
- http://msdn.microsoft.com/en-us/library/04y282hb.aspx- http://www.youtube.com/watch?v=3Pbj7pRcu4I
To create DataSet using Visual Studio 2010: (It is slightly different for Visual Studio 2012)
For dsNorthwindShippers:
- Select the App_Code directory in the Solution Explorer- Right Click App_Code- Select Add New Item- Select DataSet- Enter dsNorthwindShippers for the Name- Click Add Button- Go to Server Explorer- Expand Data Connections- Expand you Northwind Connection- Expand Tables- Drag Shippers onto the Dataset Designer- Save
For dsNorthwindRegion:
- Select the App_Code directory in the Solution Explorer- Right Click App_Code- Select Add New Item- Select DataSet- Enter dsNorthwindRegion for the Name- Click Add Button- Go to Server Explorer- Expand Data Connections- Expand you Northwind Connection- Expand Tables- Drag Region onto the Dataset Designer- Save
If you have problems implementing my instructions, you are really going to have to ask your boss for help and direction.
protected void Page_Load(object sender, EventArgs e){ DataView view = Region_ISDataSource.Select() as DataView; Regions_WebCombo.PopulateUnboundData(view, true); }
Please have kindly have review on the modified sample to see the result.
You also can see on WebGrid sample, UsingWebComboNETwithMultipleSelection.aspx. This sample have similar scenario with your current scenario.
Thank you.
Regards,
Hans.
protected void WebGrid1_InitializeRow(object sender, ISNet.WebUI.WebGrid.RowEventArgs e){ e.Row.Cells.GetNamedItem("Roles").Value = 1; e.Row.Cells.GetNamedItem("Roles").Text = "Research Staff"; }
And the result is the sample work fine on my end. Please kindly have a review on this modified sample as well.
To run the sample you just simple add/attach the page/file to WebGrid sample project.
Thank you very much.
Per your instructions I got it to check intialized values by adding BoundMode="ForceUnbound" to WebCombo.LayoutSettings but that revealed a new problem.
<LayoutSettings ComboMode="SingleColumn" TextBoxMode="ReadOnly" BoundMode="ForceUnbound" >
For the initialized values, when they are unchecked in the DropDown they are not removed from the TextBox. See attached screen shots.
For new checked items, they are added and removed as unchecked.
What else do I need to do?
Hello,Thank you for reply.Perhaps you could you use this work around to fix this issue. I add some validation code in OnItemChecked client side event. Here’s how I implement the validation code:
function Regions_WebCombo_OnItemChecked(){ var Regions_WebCombo = ISGetObject("Regions_WebCombo"); var Values = Regions_WebCombo.GetMultipleValues(); var Rows = Regions_WebCombo.GetRows(); var rowsLenght = Rows.length; var selectedRow = Regions_WebCombo.GetSelectedRow(); var selectedRowValue = selectedRow.dataValue; var selectedRowChecked = selectedRow.childNodes[0].childNodes[0].checked; if (Values) { var valuesLength = Values.length; for (var i = 0; i < valuesLength; i++) { var valueItem = Values[i]; if (valueItem) { if (valueItem.Value == selectedRowValue && selectedRowChecked == true) { Values.splice(i, 1); } } } } Regions_WebCombo.UpdateUI(); } function Regions_WebCombo_OnShowDropDown(controlId) { var Regions_WebCombo = ISGetObject("Regions_WebCombo"); Regions_WebCombo.LayoutSettings.ClientSideEvents.OnItemChecked = "Regions_WebCombo_OnItemChecked"; }
I have modified your sample as well. Please kindly have review on the sample to see the result.Thank you very much.Regards,Hans.
Hello,Related to the “Unchecked Item” issue, after I investigate furthermore, it seems the issue occurs due to database value and data type itself.I have tried to bind the unbound column to another table (Categories table). I set the DataValue to “CategoryID” and DataText to “CategoryName”.The result is the “Unchecked Item” issue doesn’t occur, even without validation code that I wrote in my prior post.It happens due to the differences between data type in RegionDescription and data type in CategoryName.The data type of RegionDescription is “nchar” and data type of CategoryName is “nvarchar”.As we know, ‘char’ data type is used for storing fix length character strings. ‘Char’ will add the spacebar to the blank space. Unlike the ‘varchar’ data type, it will not add the spacebar to the blank space (Char_VarChar.jpg)However, in WebGrid’s InitializeRow server side event, we add the value text without blank space.It will cause the “Unchecked Item” issue occur, due to the value in database and the value in WebCombo doesn’t match. In my humble opinion, I suggest you to modify your database that using ‘char’ data type to use ‘varchar’ data type.Because as far I know the ‘char’ data type will also cause an issue / problem, when you want to do some databases query.I attached the modified sample that using Categories table as well.Thank you.Regards,Hans.
How do I filter the List Items in the Unbound WebCombo?
I tried to use the WebCombo Client Side Method SetAdditionalFilters in the WebGrid ClientSideEvent OnEnterEditMode based on a value in the row but on the first time a row is selected it does not filter and on subsequent rows selected nothing is in the Drop Down List.
I modified the last code you supplied.
<ClientSideEvents OnEnterEditMode="WebGrid1_OnEnterEditMode" />
<script language="javascript" type="text/javascript"> function WebGrid1_OnEnterEditMode(controlId, TableName, editObject) { var _WebGrid = ISGetObject(controlId); var _WebGridCell = editObject.ToCellObject(); if (_WebGridCell.Name == "Roles") { var _WebCombo = editObject.element; var FilterValue_String ; var EmployeeID_String = _WebGridCell.Row.GetCell("EmployeeID").Value if (true) { switch (EmployeeID_String) { case "1": FilterValue_String = "1"; break; default: FilterValue_String = "2"; } _WebCombo.SetAdditionalFilters("[RoleId] = " + FilterValue_String); } else { switch (EmployeeID_String) { case "1": FilterValue_String = "Research Staff"; break; default: FilterValue_String = "Research Manager"; } _WebCombo.SetAdditionalFilters("[RoleName] = " + "'" + FilterValue_String + "'"); } _WebCombo.SetText(_WebGridCell.Text, true); } return true; } </script>
Please see attached screenshots and code.
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