Telerik radGridを使用して、住所などのデータを表示しています。新しいアドレスを挿入したり、既存のアドレスを編集したりできるようにしたい。この目的のために、次のデータを事前入力するカスケードコンボボックスを使用したいと思います。つまり、country_onselectedindexchangedはProvince/Stateなどに入力します。
私の問題は、Countryをクリックするたびに、Province / Stateコンボが入力されていることをステップスルーで確認できますが、ポストバックが発生し、Grid_itemdataboundイベントが発生し、初期データが再度入力されることです。
Telerikサイトにアカウントを持っていますが、前回質問を投稿したとき、回答が得られるまでに1週間かかりました。
<telerik:RadGrid ID="RecipientsGrid" runat="server" AutoGenerateColumns="false" EnableViewState="true" PageSize="5"
AllowFilteringByColumn="true" AllowPaging="true" AllowSorting="True">
<ClientSettings EnablePostBackOnRowClick="true">
<Selecting AllowRowSelect="true" />
</ClientSettings>
<MasterTableView CommandItemDisplay="Bottom" DataKeyNames="RecipientOrganizationID" EditMode="EditForms" >
<EditFormSettings EditFormType="Template">
<FormTemplate>
<telerik:RadComboBox ID="CountryCombo" runat="server" DataTextField="CountryName" DataValueField="CountryID"
OnSelectedIndexChanged="CountryCombo_SelectedIndexChanged" AutoPostBack="true">
</telerik:RadComboBox>
<telerik:RadComboBox ID="ProvinceCombo" runat="server" Width="325" EnableLoadonDemand="true" OnSelectedIndexChanged="ProvinceCombo_SelectedIndexChanged" AutoPostBack="true" >
</telerik:RadComboBox>
</FormTemplate>
</EditFormSettings>
</MasterTableView>
</telerik:RadGrid>
Private Sub RecipientsGrid_NeedDataSource(sender As Object, e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles RecipientsGrid.NeedDataSource
Dim ctx As New DataEntities
RecipientsGrid.DataSource = ctx.RecipientOrganizations.ToList
AddOrganizationButton.Visible = False
RecipientOrganizationComboBox.Visible = False
End Sub
Private Sub RecipientsGrid_ItemDataBound(sender As Object, e As Telerik.Web.UI.GridItemEventArgs) Handles RecipientsGrid.ItemDataBound
If TypeOf e.Item Is GridEditableItem AndAlso e.Item.IsInEditMode Then
Dim editedItem As GridEditableItem = TryCast(e.Item, GridEditableItem)
If e.Item.OwnerTableView.IsItemInserted Then
Dim CountryCombo As RadComboBox = TryCast(editedItem.FindControl("CountryCombo"), RadComboBox)
Dim ProvinceCombo As RadComboBox = TryCast(editedItem.FindControl("ProvinceCombo"), RadComboBox)
Dim CityCombo As RadComboBox = TryCast(editedItem.FindControl("CityCombo"), RadComboBox)
LoadCountries(CountryCombo)
Else
End If
End If
End Sub
Protected Sub CountryCombo_SelectedIndexChanged(ByVal sender As Object, ByVal e As RadComboBoxSelectedIndexChangedEventArgs)
Dim CountryCombo As RadComboBox = DirectCast(sender, RadComboBox)
Dim editedItem As GridEditableItem = DirectCast(TryCast(sender, RadComboBox).NamingContainer, GridEditableItem)
Dim ProvinceCombo As RadComboBox = DirectCast(editedItem.FindControl("ProvinceCombo"), RadComboBox)
LoadProvinces(e.Value, ProvinceCombo)
End Sub
Protected Sub ProvinceCombo_SelectedIndexChanged(ByVal sender As Object, ByVal e As RadComboBoxSelectedIndexChangedEventArgs)
Dim ProvinceCombo As RadComboBox = DirectCast(sender, RadComboBox)
Dim editedItem As GridEditableItem = DirectCast(TryCast(sender, RadComboBox).NamingContainer, GridEditableItem)
Dim CityCombo As RadComboBox = DirectCast(editedItem.FindControl("CityCombo"), RadComboBox)
LoadCities(e.Value, CityCombo)
End Sub
Protected Sub LoadCountries(ByVal Control As RadComboBox)
Using context As New DataEntities
With Control
.DataValueField = "CountryId"
.DataTextField = "CountryName"
.DataSource = context.Countries.OrderBy(Function(x) x.displayOrder).ToList
End With
Control.Width = Unit.Pixel(320)
Control.DataBind()
End Using
End Sub
Protected Sub LoadProvinces(ByVal countryID As Integer, ByVal Control As RadComboBox)
Using context As New DataEntities
With Control
.DataValueField = "ProvinceId"
.DataTextField = "NameEnglish"
.DataSource = context.Provinces.Where(Function(x) x.CountryId = countryID).OrderBy(Function(x) x.NameEnglish).ToList
End With
Control.Width = Unit.Pixel(320)
Control.DataBind()
End Using
End Sub
Protected Sub LoadCities(ByVal ProvinceId As Integer, ByVal Control As RadComboBox)
Using context As New DataEntities
With Control
.DataValueField = "CityId"
.DataTextField = "CityName"
.DataSource = context.Cities.Where(Function(x) x.ProvinceID = ProvinceId).OrderBy(Function(x) x.CityName).ToList
End With
Control.Width = Unit.Pixel(320)
Control.DataBind()
End Using
End Sub
Public Sub SetComboBoxDefault(ByVal FindItemByValue As Integer, ByVal Control As RadComboBox, ByVal DisplayText As String)
Dim ComboBoxItem As RadComboBoxItem
If FindItemByValue > 0 Then
ComboBoxItem = Control.FindItemByValue(FindItemByValue)
If ComboBoxItem IsNot Nothing Then
ComboBoxItem.Selected = True
Else
Control.Items.Insert(0, New RadComboBoxItem("-- Please select a " & DisplayText & " --", String.Empty))
End If
Else
Control.Items.Insert(0, New RadComboBoxItem("-- Please select a " & DisplayText & " --", String.Empty))
End If
End Sub