ITPub博客

首页 > 应用开发 > IT综合 > Select a matching row of WebCombo control based on DataValue

Select a matching row of WebCombo control based on DataValue

原创 IT综合 作者:yuzhangqi 时间:2010-08-27 10:23:49 0 删除 编辑

Considering the following scenario:The user selected an item in a WebCombo control then do a "save" action, when he re-enter this page, we want the Webcombo control select the value matching the data from the database.

Let's look at an example as below.

Supposed that the "Service" WebCombo has a DataTextField named "Code" and a DataValueField named "ID". Now we want to select a row by matching the DataValue of the control. Normally the code looks like below.

Dim serviceValue as String = LoadServiceValueFromDatabse()

ServiceWebCombo.DataValue = serviceValue

However, this did not work for WebCombo control.

Let's try another way as below to see if it will work.

Dim cell As New UltraGridCell
cell = ServiceWebCombo.FindByValue(strTempSetting)
If Not cell Is Nothing Then
ServiceWebCombo.SelectedIndex = cell.Row.Index
End If

However cell object returns Nothing,that's to say we can not find the matching DataValue. This way is not feasible.

Now Let's try this way: iterate items of WebCombo control to find the matching item, if found then select it, else none is selected. The code looks like below.

Private Sub SelectWebComboItem(ByRef control As WebCombo, ByVal dataValue As String)
For Each row As UltraGridRow In control.Rows
If row.Cells(1).Value.ToString().Equals(dataValue) Then
control.SelectedIndex = row.Index
Exit For
End If
Next
End Sub

If you don't like this approach, there is an alternative you can choise - using client side javascript api to select matching data value.

Supposed we have got the DataValue to match from server side in client side. First we got the client WebCombo Object using the utility function igcmbo_getComboById().

var serviceValue;

var oCombo = igcmbo_getComboById('ServiceWebCombo');

then using setDataValue() to select the matching row in the drop-down.

oCombo.setDataValue(serviceValue) ;

If you can get the row index of the matching row, you can code as such.

oCombo.setSelectedIndex(index);

If you want to select a row by matching the DisplayValue property of WebCombo control, it is very easy.

Server side code:

ServiceWebCombo.DisplayValue =

Client side code:

oCombo.setDisplayValue();

References:

http://help.infragistics.com/Help/NetAdvantage/ASPNET/2009.1/CLR3.5/html/WebCombo_Object_CSOM.html

http://help.infragistics.com/Help/NetAdvantage/ASPNET/2010.2/CLR4.0/html/Infragistics4.WebUI.WebCombo.v10.2~Infragistics.WebUI.WebCombo.WebCombo_members.html

[@more@]

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/13651903/viewspace-1037465/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2008-06-10

  • 博文量
    102
  • 访问量
    763298