This is a migrated thread and some comments may be shown as answers.

RadGrid disappears when adding or editing record when inside a user control

4 Answers 277 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Humberto
Top achievements
Rank 1
Humberto asked on 01 Dec 2010, 02:30 AM
I have a radgrid inside a user control that disappears when in edit mode or add new mode.   works just fine when the grid is inside an aspx page but when placed inside an ascx, it breaks.  any ideas?

4 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 01 Dec 2010, 06:53 AM
Hello,


I assume that you are using Simple databinding technique to populate the grid and not databinding in corresponding events. A better approach is using Advanced-Databinding by attaching NeedDataSource event to grid.

Go through the following links:
Documentation
Demo



-Shinu.
0
Humberto
Top achievements
Rank 1
answered on 01 Dec 2010, 11:26 AM
i am using simple databinding and using the built-in need data source method.   The grid shows when the form first loads but then disappears when trying to add a new record or in edit mode, as if it's losing it's event handler because they are not firing. below is the code behind:

Partial

 

Class CreateEditPartnerAllotment

 

 

'Inherits BaseGrid(Of Allotment)

 

 

'Inherits System.Web.UI.UserControl

 

 

Inherits Citrix.MyCitrix.Licensing.LicensingBaseControl

 

 

 

#Region

 

"Private Variables"

 

 

Private pExportFilename As String = "CitrixExams"

 

 

Private pErrorMsg_Duplicated As String = "Exam code already exists. Please try a different exam code."

 

 

Private pErrorMsg_Insert As String = "Error saving new Exam to the database."

 

 

Private pErrorMsg_Update As String = "Error saving the Exam to the database."

 

 

Private pErrorMsg_Linked As String = "Exam code is linked to a candidate. Please remove all links and try again."

 

 

Private pErrorMsg_Delete As String = "Error deleting the Exam from the database."

 

 

Private pErrorMsg_Search As String = "Error searching for Exams."

 

 

Private pErrorMsg_Export As String = "Error exporting the Exams."

 

 

Private pErrorMsg_Render As String = "Error rendering the Exams."

 

 

Private pErrorMsg_Datasource As String = "Error retrieving the Exams from the database."

 

 

Private pErrorMsg_ItemCommand As String = "Error processing specified command."

 

 

Private pErrorMsg_Prefix As String = "Exam series code CANNOT begin with CT_."

 

 

Private pPrefix As String = "CT_"

 

 

Private pCancelEdition As Boolean = False

 

 

Private pCancelInsertion As Boolean = False

 

 

Private pClearSearch As Boolean = False

 

 

 

Private pErrorMsg_MissingQuantity As String = "Quantity must me entered."

 

 

Private pErrorMsg_MissingUserCount As String = "User Count must me entered."

 

 

Private pErrorMsg_MissingProduct As String = "Product must me selected."

 

 

Private pErrorMsg_MissingAuthLevel As String = "Authorization Level must me entered."

 

 

Private pSuccess_Saved As String = "Your allotment configuration has been saved."

 

 

Private pFailure_Saved As String = "Your allotment was not saved."

 

 

Private pAllotmentID As Integer

 

#End

 

Region

 

#Region

 

"Public properties"

 

 

Public Property allotmentID() As Integer

 

 

Get

 

 

Dim oAllotmentID As Integer = 0

 

 

Integer.TryParse(Request.QueryString("id"), oAllotmentID)

 

 

'Return oAllotmentID

 

 

Return 5993

 

 

End Get

 

 

Set(ByVal Value As Integer)

 

pAllotmentID = Value

hdnProdReleaseID.Value = Value

 

'Me.pAllotmentItems = getPartnerAllotmentRules(hdnProdReleaseID.Value)

 

 

'Me.rgGrid.DataSource = GetDataSource()

 

 

Me.rgGrid.Visible = True

 

 

'Me.rgGrid.Rebind()

 

 

End Set

 

 

End Property

 

#End

 

Region

 

 

#Region

 

"Page Events"

 

 

Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init

 

 

'Me.pPageTitle = "Exam Management"

 

 

'LocalizePagerStrings()

 

 

End Sub

 

 

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

 

pnlErrorMessage.Visible =

False

 

 

If Not IsPostBack Then

 

 

'Set initial values.

 

 

'pSessionData.SearchCriteria = String.Empty

 

 

'pSessionData.Exams = Nothing

 

 

'rgGrid.MasterTableView.SortExpressions.Clear()

 

 

'Dim tmpSortExpression As New GridSortExpression

 

 

'tmpSortExpression.FieldName = "SeriesId"

 

 

'tmpSortExpression.SortOrder = GridSortOrder.Ascending

 

 

'rgGrid.MasterTableView.SortExpressions.Add(tmpSortExpression)

 

PopulateLanguageDropDown(5713)

 

End If

 

 

Try

 

 

'Edit in-place.

 

 

With rgGrid.MasterTableView

 

 

'Edit in place.

 

.EditMode = GridEditMode.InPlace

 

'When inserting, open edit boxes at top of the current page.

 

.InsertItemDisplay = GridInsertItemDisplay.Top

.InsertItemPageIndexAction = GridInsertItemPageIndexAction.ShowItemOnCurrentPage

.PagerStyle.AlwaysVisible =

True

 

 

End With

 

 

'DataBind()

 

 

Catch ex As Exception

 

HandleException(ex,

"Page_Load", "ExamManager.aspx.vb")

 

 

'Show error message.

 

ShowMessage(ex.Message)

 

End Try

 

 

 

End Sub

 

 

#End

 

Region

 

#Region

 

"Grid Events"

 

 

Protected Sub rgGrid_DeleteCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles rgGrid.DeleteCommand

 

 

Try

 

 

'Get user input data.

 

 

If (TypeOf e.Item Is GridDataItem) Then

 

 

Dim oAllotment As Citrix.CRM.Core.Allotment = GetControlValues(e.Item)

 

DeleteAllotment(oAllotment)

 

'Show error message.

 

 

'showmessage(pErrorMsg_Delete)

 

 

'e.Canceled = True

 

 

End If

 

 

'End If

 

 

Catch ex As Exception

 

HandleException(ex,

"rgGrid_DeleteCommand", "CertificationManager.aspx.vb")

 

 

'Show error message.

 

ShowMessage(pErrorMsg_Delete)

e.Canceled =

True

 

 

End Try

 

 

End Sub

 

 

Protected Sub rgGrid_RetrieveDataSource(ByVal source As Object, ByVal e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles rgGrid.NeedDataSource

 

 

'Populate the exams grid.

 

 

Try

 

rgGrid.DataSource = GetDataSource()

 

Catch ex As Exception

 

HandleException(ex,

"rgGrid_RetrieveDataSource", "ExamManager.aspx.vb")

 

ShowMessage(pErrorMsg_Datasource)

 

End Try

 

 

End Sub

 

 

Protected Function GetDataSource() As List(Of Citrix.CRM.Core.Allotment)

 

 

'Dim oRules As List(Of Citrix.CRM.Core.Allotment) = CType(Me.Page, DownloadsBasePage).GetPartnerAllotmentRulesByID(5993).ToList()

 

 

Dim oRules2 As List(Of Citrix.CRM.Core.Allotment) = GetPartnerAllotmentRulesByTypeAndProdRlsID("NFR", 5713).ToList()

 

 

Return oRules2

 

 

End Function

 

 

Protected Sub rgGrid_ItemCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles rgGrid.ItemCommand

 

 

Try

 

 

'No row selected. Header/Pager commands.

 

 

Select Case e.CommandName

 

 

Case "ClearSearch"

 

pCancelEdition =

True

 

pCancelInsertion =

True

 

 

'rgGrid_ClearSearchCommand(source, e)

 

 

Case "Search"

 

pCancelEdition =

True

 

pCancelInsertion =

True

 

 

'rgGrid_SearchCommand(source, e)

 

 

Case RadGrid.EditCommandName, RadGrid.EditAllCommandName

 

pCancelEdition =

False

 

pCancelInsertion =

True

 

 

Case RadGrid.InitInsertCommandName, RadGrid.DeleteCommandName, RadGrid.DeleteSelectedCommandName

 

pCancelEdition =

True

 

pCancelInsertion =

False

 

 

Case RadGrid.PageCommandName

 

 

'Command parameter has the page number.

 

 

Case RadGrid.PerformInsertCommandName

 

 

'After successful insert exit from insert mode.

 

 

Case RadGrid.CancelCommandName, RadGrid.CancelAllCommandName

 

pCancelEdition =

True

 

pCancelInsertion =

True

 

 

Case RadGrid.ExportToExcelCommandName

 

pCancelEdition =

True

 

pCancelInsertion =

True

 

 

'Call the event handler.

 

 

'clbExport2Excel_Click(source, e)

 

 

Case RadGrid.DeleteCommandName, RadGrid.DeleteSelectedCommandName

 

pCancelEdition =

True

 

pCancelInsertion =

True

 

 

End Select

 

 

Catch ex As Exception

 

HandleException(ex,

"rgGrid_ItemCommand", "ExamManager.aspx.vb")

 

 

'Show error message.

 

ShowMessage(pErrorMsg_ItemCommand)

e.Canceled =

True

 

 

End Try

 

 

End Sub

 

 

Protected Sub rgGrid_ItemCreated(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles rgGrid.ItemCreated

 

 

'Cancel edit controls.

 

 

If pCancelEdition Then

 

 

Dim grid As RadGrid = CType(sender, RadGrid)

 

 

If (grid.EditItems.Count > 0) Then

 

grid.MasterTableView.ClearEditItems()

 

End If

 

 

End If

 

 

'Disable inserted row.

 

 

If pCancelInsertion Then

 

e.Item.OwnerTableView.IsItemInserted =

False

 

 

End If

 

 

'Disable Show All link and clear search text.

 

 

If pClearSearch Then

 

 

Dim txtSearch As TextBox = TryCast(e.Item.FindControl("txtSearch"), TextBox)

 

 

If txtSearch IsNot Nothing Then

 

txtSearch.Text =

String.Empty

 

 

End If

 

 

End If

 

 

Dim lbtnClearSearch As LinkButton = TryCast(e.Item.FindControl("lbtnClearSearch"), LinkButton)

 

 

If lbtnClearSearch IsNot Nothing Then

 

lbtnClearSearch.Visible = pClearSearch

 

End If

 

 

If TypeOf e.Item Is GridPagerItem Then

 

 

Dim pagerItem As GridPagerItem = CType(e.Item, GridPagerItem)

 

 

Dim nxtButton As LinkButton = CType(pagerItem.FindControl("lbNext"), LinkButton)

 

 

If rgGrid.MasterTableView.PagingManager.IsLastPage Then

 

nxtButton.Enabled =

False

 

 

Else

 

nxtButton.Enabled =

True

 

 

End If

 

 

Dim prvButton As LinkButton = CType(pagerItem.FindControl("lbPrevious"), LinkButton)

 

 

If rgGrid.MasterTableView.PagingManager.IsFirstPage Then

 

prvButton.Enabled =

False

 

 

Else

 

prvButton.Enabled =

True

 

 

End If

 

 

End If

 

 

End Sub

 

 

Protected Sub rgGrid_ItemDataBound(ByVal sender As Object, ByVal e As GridItemEventArgs) Handles rgGrid.ItemDataBound

 

 

Try

 

 

If (TypeOf e.Item Is GridCommandItem) Then

 

 

Dim commandItem As GridCommandItem = CType(e.Item, GridCommandItem)

 

 

'Show header command items.

 

 

If (TypeOf commandItem.NamingContainer Is GridTHead) Then

 

 

Dim txtSearch As TextBox = TryCast(commandItem.FindControl("txtSearch"), TextBox)

 

 

If txtSearch IsNot Nothing Then

 

 

'txtSearch.Text = pSessionData.SearchCriteria

 

 

End If

 

 

End If

 

 

ElseIf (TypeOf e.Item Is GridPagerItem) Then

 

 

'Set proper page size.

 

 

If (TypeOf e.Item.NamingContainer Is GridTFoot) Then

 

 

Dim ddlPageSize As RadComboBox = TryCast(e.Item.FindControl("ddlPageSize"), RadComboBox)

 

 

If ddlPageSize IsNot Nothing Then

 

ddlPageSize.SelectedValue = rgGrid.MasterTableView.PageSize

 

End If

 

 

'Citrix.MyCitrix.Controls.CommonFuncs.LocalizePagerControl(Me.rgGrid, e, "ddlPageSize", "lbPrevious", "lbNext", "lblContactsPageLabel", RadGridPagerPrevPageText, RadGridPagerNextPageText, RadGridPagerPageCountText, "rgGrid_ItemDataBound", Me.pPerson.Login)

 

 

End If

 

 

ElseIf (TypeOf e.Item Is GridDataInsertItem) Then

 

 

'Populate default values.

 

BindDropdowns(e.Item,

New Citrix.CRM.Core.Allotment)

 

 

ElseIf (TypeOf e.Item Is GridDataItem) Then

 

 

'Binding dropdown lists.

 

BindControls(e.Item,

DirectCast(e.Item.DataItem, Citrix.CRM.Core.Allotment))

 

 

Dim dataItem As GridDataItem = CType(e.Item, GridDataItem)

 

 

Dim lbl As Label = TryCast(dataItem.FindControl("lblExamName"), Label)

 

 

Dim examName As String = String.Empty

 

 

If lbl IsNot Nothing Then

 

examName = lbl.Text

 

End If

 

 

Dim button As ImageButton = CType(dataItem("DeleteColumn").Controls(0), ImageButton)

 

 

'button.Attributes("onclick") = String.Empty

 

button.Attributes(

"onclick") = String.Format("if(!$find('rgGrid').confirm('Delete "{0}" Allotment?', event, 'Delete Allotment'))return false;", examName)

 

 

End If

 

 

'Set focus on the first textbox on edit.

 

 

If (TypeOf e.Item Is GridEditableItem AndAlso e.Item.IsInEditMode) Then

 

 

Dim txt As TextBox = TryCast(e.Item.FindControl("txtExamCode"), TextBox)

 

 

If txt IsNot Nothing Then

 

txt.Focus()

 

End If

 

 

End If

 

 

Catch ex As Exception

 

HandleException(ex,

"rgGrid_ItemDataBound", "ExamManager.aspx.vb")

 

 

'Show error message.

 

ShowMessage(pErrorMsg_Render)

e.Canceled =

True

 

 

End Try

 

 

End Sub

 

 

Protected Sub rgGrid_UpdateCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles rgGrid.UpdateCommand

 

 

'Check the data input is valid.

 

Page.Validate()

 

If Not Page.IsValid Then

 

e.Canceled =

True

 

 

Return

 

 

End If

 

 

Try

 

 

If (TypeOf e.Item Is GridEditableItem) Then

 

 

Dim editedItem As GridEditableItem = TryCast(e.Item, GridEditableItem)

 

 

'Set new values

 

 

Dim oAllotment As CRM.Core.Allotment = GetControlValues(e.Item) 'Get user input data.

 

 

Dim errorMsg As String = String.Empty

 

 

If IsDataValid(oAllotment, False, errorMsg) Then

 

 

'Insert exam.

 

 

If Not UpdatePartnerEvalRule(oAllotment) Then

 

ShowMessage(pFailure_Saved)

e.Canceled =

True

 

 

Else

 

ShowMessage(pSuccess_Saved)

 

End If

 

 

Else

 

ShowMessage(errorMsg)

e.Canceled =

True

 

 

End If

 

 

End If

 

 

Catch ex As Exception

 

HandleException(ex,

"rgGrid_UpdateCommand", "ExamManager.aspx.vb")

 

 

'Show error message.

 

ShowMessage(pErrorMsg_Update)

e.Canceled =

True

 

 

End Try

 

 

End Sub

 

 

 

Protected Sub rgGrid_InsertCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles rgGrid.InsertCommand 'Protected Sub rgAllotments_InsertCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles rgAllotments.InsertCommand

 

 

'Check the data input is valid.

 

Page.Validate()

 

If Not Page.IsValid Then

 

e.Canceled =

True

 

 

Return

 

 

End If

 

 

Dim editedItem As GridEditableItem = TryCast(e.Item, GridEditableItem)

 

 

'Set new values

 

 

Try

 

 

Dim newAllotment As CRM.Core.Allotment = GetControlValues(editedItem)

 

 

Dim errorMsg As String = String.Empty

 

 

If IsDataValid(newAllotment, True, errorMsg) Then

 

 

'Insert exam.

 

 

If Not UpdatePartnerEvalRule(newAllotment) Then

 

ShowMessage(pErrorMsg_Insert)

e.Canceled =

True

 

 

End If

 

 

Else

 

ShowMessage(errorMsg)

e.Canceled =

True

 

 

End If

 

 

Catch ex As Exception

 

HandleException(ex,

"rgGrid_InsertCommand", "PartnerAllotment.aspx.vb")

 

 

'Show error message.

 

ShowMessage(pErrorMsg_Insert)

e.Canceled =

True

 

 

End Try

 

 

End Sub

 

#End

 

Region

 

#Region

 

"Private methods"

 

 

Private Overloads Sub HandleException(ByVal ex As System.Exception, ByVal method As String, ByVal inWebPage As String, Optional ByVal inErrorCode As Integer = Integer.MinValue)

 

 

' MyBase.HandleException(ex, "Citrix.MyCitrix.PAC.ExamCertManager", method, inWebPage, inErrorCode)

 

 

End Sub

 

 

Public Function DeleteAllotment(ByVal inAllotment As Citrix.CRM.Core.Allotment) As Boolean

 

 

Try

 

 

Dim oSaveStatus As Boolean = False

 

oSaveStatus =

CType(Me.Page, DownloadsBasePage).DeletePartnerEvalRule(inAllotment)

 

 

If oSaveStatus Then

 

ShowMessage(pSuccess_Saved)

 

Else

 

ShowMessage(pFailure_Saved)

 

End If

 

 

 

Catch ex As Exception

 

 

Throw New CitrixException(ex.Message, "TestPartnerAllotment", "DeleteAllotment")

 

 

End Try

 

 

Return False 'Some error occurred.

 

 

End Function

 

 

Protected Function UpdatePartnerEvalRule(ByVal inAllotmentRule As CRM.Core.Allotment) As Boolean

 

 

Dim oSaveStatus As Boolean = False

 

oSaveStatus =

CType(Me.Page, DownloadsBasePage).createPartnerEvalRules(inAllotmentRule)

 

 

'If oSaveStatus Then

 

 

' ShowMessage(pSuccess_Saved)

 

 

'Else

 

 

' ShowMessage(pFailure_Saved)

 

 

'End If

 

 

Return oSaveStatus

 

 

End Function

 

 

Private Sub ShowMessage(ByVal inMessage As String)

 

 

If Not String.IsNullOrEmpty(inMessage) Then

 

 

Me.lblErrorMessage.Text = inMessage

 

 

Me.pnlErrorMessage.Visible = True

 

 

Else

 

HideMessage()

 

End If

 

 

End Sub

 

 

Private Sub HideMessage()

 

 

Me.lblErrorMessage.Text = String.Empty

 

 

Me.pnlErrorMessage.Visible = False

 

 

End Sub

 

 

 

Private Function GetControlValues(ByVal item As GridDataItem) As CRM.Core.Allotment

 

 

Dim oAllotment As CRM.Core.Allotment = Nothing

 

 

Try

 

oAllotment = GetAllotmentById(item)

 

If item.IsInEditMode Then

 

 

'oAllotment.CtViewableSNID = ""

 

 

'Get lists.

 

 

Dim ddlist As Citrix.MyCitrix.Codeset = TryCast(item.FindControl("ddlProduct"), Citrix.MyCitrix.Codeset)

 

 

If ddlist IsNot Nothing Then

 

oAllotment.Product = ddlist.SelectedValue

 

End If

 

ddlist =

TryCast(item.FindControl("ddlAuthorizationLevel"), Codeset)

 

 

If ddlist IsNot Nothing Then

 

oAllotment.AuthorizationLevel = ddlist.SelectedValue

 

End If

 

 

'Get textboxes.

 

 

Dim txt As TextBox = TryCast(item.FindControl("txtQuantity"), TextBox)

 

 

If txt IsNot Nothing Then

 

oAllotment.Quantity = txt.Text

 

End If

 

txt =

TryCast(item.FindControl("txtUserCount"), TextBox)

 

 

If txt IsNot Nothing Then

 

oAllotment.UserCount = txt.Text

 

End If

 

oAllotment.ProdRelLangID = ddlLanguage.SelectedValue

oAllotment.CreatedBy = Request.ServerVariables(

"LOGON_USER")

 

 

'oAllotment.ProductReleaseID = Session.Item(STR_PRODUCT_RELEASE_ID)

 

 

'oAllotment.PartNumberID = Session.Item(STR_PART_NUMBER)

 

oAllotment.ProductReleaseID = 1260

oAllotment.PartNumberID =

"1260"

 

 

Else

 

 

Dim lbl As Label = TryCast(item.FindControl("lblProduct"), Label)

 

 

If lbl IsNot Nothing Then

 

oAllotment.Product = lbl.Text

 

End If

 

lbl =

TryCast(item.FindControl("lblAuthorizationLevel"), Label)

 

 

If lbl IsNot Nothing Then

 

oAllotment.AuthorizationLevel = lbl.Text

 

End If

 

lbl =

TryCast(item.FindControl("lblQuantity"), Label)

 

 

If lbl IsNot Nothing Then

 

oAllotment.Quantity = lbl.Text

 

End If

 

lbl =

TryCast(item.FindControl("lblUserCount"), Label)

 

 

If lbl IsNot Nothing Then

 

oAllotment.UserCount = lbl.Text

 

End If

 

oAllotment.LicenseDistributionType =

"Partner Demo"

 

 

'oAllotment.ProductDefinitionType = hdnProductDefinitionType.Value

 

 

'oAllotment.ProductDefinition = hdnProductName.Value

 

oAllotment.PartNumberID =

Me.hdnPartNumber.Value

 

 

If oAllotment.PartNumberID Is Nothing Then

 

oAllotment.PartNumberID =

"1"

 

 

End If

 

 

'oAllotment.ProductReleaseID = hdnProdReleaseID.Value

 

oAllotment.ProdRelLangID = ddlLanguage.SelectedValue

 

If IsDate(tkEffectiveDate.SelectedDate) Then

 

oAllotment.EffectiveDate = tkEffectiveDate.SelectedDate

 

End If

 

 

If IsDate(tkReplenishAfterDate.SelectedDate) Then

 

oAllotment.ExpirationDate = tkReplenishAfterDate.SelectedDate

 

End If

 

oAllotment.BuildToOrder = rblBuildToOrder.SelectedValue

 

If IsDate(tkReplenishAfterDate.SelectedDate) Then

 

oAllotment.ReplenishAfterDate = tkReplenishAfterDate.SelectedDate

 

End If

 

oAllotment.CreatedBy = Request.ServerVariables(

"LOGON_USER")

 

 

 

End If

 

 

Catch ex As Exception

 

HandleException(ex,

"GetControlValues", "ExamManager.aspx.vb")

 

 

'Show error message.

 

ShowMessage(ex.Message)

 

End Try

 

 

Return oAllotment

 

 

End Function

 

 

Private Sub BindControls(ByVal item As GridDataItem, ByVal oAllotment As Citrix.CRM.Core.Allotment)

 

 

Try

 

 

If item.IsInEditMode Then

 

 

'Binding dropdown lists.

 

BindDropdowns(item, oAllotment)

 

'Binding textboxes.

 

 

Dim txt As TextBox = TryCast(item.FindControl("txtQuantity"), TextBox)

 

 

If Not (txt Is Nothing OrElse String.IsNullOrEmpty(oAllotment.Quantity)) Then

 

txt.Text = oAllotment.Quantity

 

End If

 

txt =

TryCast(item.FindControl("txtUserCount"), TextBox)

 

 

If Not (txt Is Nothing OrElse String.IsNullOrEmpty(oAllotment.UserCount)) Then

 

txt.Text = oAllotment.UserCount

 

End If

 

 

'txt = TryCast(item.FindControl("txtctViewableSNID"), TextBox)

 

 

'If Not (txt Is Nothing OrElse String.IsNullOrEmpty(oAllotment.CtViewableSNID)) Then

 

 

' txt.Text = oAllotment.CtViewableSNID

 

 

'End If

 

 

Dim lbl As Label = TryCast(item.FindControl("lblctViewableSNIDReadOnly"), Label)

 

 

If Not (lbl Is Nothing OrElse String.IsNullOrEmpty(oAllotment.CtViewableSNID)) Then

 

lbl.Text = oAllotment.CtViewableSNID

 

End If

 

 

If oAllotment.ProdRelLangID <> 0 Then

 

ddlLanguage.SelectedValue = oAllotment.ProdRelLangID

 

End If

 

 

 

Else

 

 

'Binding labels.

 

 

Dim lbl As Label = TryCast(item.FindControl("lblProduct"), Label)

 

 

If Not (lbl Is Nothing OrElse String.IsNullOrEmpty(oAllotment.Product)) Then

 

lbl.Text = oAllotment.Product

 

End If

 

lbl =

TryCast(item.FindControl("lblAuthorizationLevel"), Label)

 

 

If Not (lbl Is Nothing OrElse String.IsNullOrEmpty(oAllotment.AuthorizationLevel)) Then

 

lbl.Text = oAllotment.AuthorizationLevel

 

End If

 

lbl =

TryCast(item.FindControl("lblQuantity"), Label)

 

 

If Not (lbl Is Nothing OrElse String.IsNullOrEmpty(oAllotment.Quantity)) Then

 

lbl.Text = oAllotment.Quantity

 

End If

 

lbl =

TryCast(item.FindControl("lblUserCount"), Label)

 

 

If Not (lbl Is Nothing OrElse String.IsNullOrEmpty(oAllotment.UserCount)) Then

 

lbl.Text = oAllotment.UserCount

 

End If

 

lbl =

TryCast(item.FindControl("lblctViewableSNID"), Label)

 

 

If Not (lbl Is Nothing OrElse String.IsNullOrEmpty(oAllotment.CtViewableSNID)) Then

 

lbl.Text = oAllotment.CtViewableSNID

 

End If

 

 

End If

 

 

If IsDate(oAllotment.EffectiveDate) And Not oAllotment.EffectiveDate.Equals(Date.MinValue) Then

 

 

Me.tkEffectiveDate.SelectedDate = oAllotment.EffectiveDate

 

 

End If

 

 

If IsDate(oAllotment.ExpirationDate) And Not oAllotment.ExpirationDate.Equals(Date.MinValue) Then

 

 

Me.tkExpirationDate.SelectedDate = oAllotment.ExpirationDate

 

 

End If

 

 

If IsDate(oAllotment.ReplenishAfterDate) And Not oAllotment.ReplenishAfterDate.Equals(Date.MinValue) Then

 

 

Me.tkReplenishAfterDate.SelectedDate = oAllotment.ReplenishAfterDate

 

 

End If

 

 

Me.rblBuildToOrder.SelectedValue = oAllotment.BuildToOrder

 

 

 

 

Catch ex As Exception

 

HandleException(ex,

"BindControls", "ExamManager.aspx.vb")

 

 

'Show error message.

 

ShowMessage(ex.Message)

 

End Try

 

 

End Sub

 

 

Private Sub PopulateLanguageDropDown(ByVal inProductReleaseID As Integer)

 

 

Dim oProductReleaseLanguageFactory As New Citrix.CRM.Core.Generic.ProductReleaseLanguageFactory

 

 

Dim oProductReleaseLanguage As CRM.Core.AbstractCRMCoreObject() = Nothing

 

 

Dim oProductReleaseLangList As New ListItem

 

 

Dim oArrayList As New System.Collections.Generic.List(Of Citrix.CRM.Core.ListItem)

 

oProductReleaseLanguage = oProductReleaseLanguageFactory.GetProductLanguageInstance(inProductReleaseID).ToArray

 

For x As Integer = 0 To oProductReleaseLanguage.Count - 1

 

 

'oProductReleaseLangList.Add(CType(oProductReleaseLanguage(x), Citrix.CRM.Core.ProductReleaseLanguage).ProductLanguage)

 

oProductReleaseLangList.ItemValue =

CType(oProductReleaseLanguage(x), Citrix.CRM.Core.ProductReleaseLanguage).ID

 

oProductReleaseLangList.ItemKey =

CType(oProductReleaseLanguage(x), Citrix.CRM.Core.ProductReleaseLanguage).ProductLanguage.LanguageName

 

oArrayList.Add(oProductReleaseLangList)

 

Next

 

 

With Me.ddlLanguage

 

.DataSource = oArrayList

.DataValueField =

"ItemValue"

 

.DataTextField =

"ItemKey"

 

.DataBind()

.Items.Insert(0,

"Select One")

 

 

End With

 

 

 

End Sub

 

 

Private Sub BindDropdowns(ByVal item As GridEditableItem, ByVal oAllotments As Citrix.CRM.Core.Allotment)

 

 

'Binding dropdown lists.

 

 

Dim oProductsArray As New ArrayList

 

 

Dim oListItemFactory As New CRM.Core.ListItemFactory

 

 

Try

 

 

Dim cslist As Codeset = TryCast(item.FindControl("ddlProduct"), Codeset)

 

 

If cslist IsNot Nothing Then

 

 

If Not String.IsNullOrEmpty(oAllotments.Product) Then

 

cslist.SelectedValue = oAllotments.Product

 

End If

 

 

End If

 

 

 

Dim cslist2 As Codeset = TryCast(item.FindControl("ddlProduct2"), Codeset)

 

 

If cslist2 IsNot Nothing Then

 

 

If Not String.IsNullOrEmpty(oAllotments.Product) Then

 

cslist2.SelectedValue = oAllotments.Product

 

End If

 

 

End If

 

 

'Dim ddl As DropDownList = item.FindControl("ddlAuthorizationLevel")

 

 

'If ddl IsNot Nothing Then

 

 

' If Not String.IsNullOrEmpty(oAllotments.AuthorizationLevel) Then

 

 

 

' ddl.SelectedValue = oAllotments.AuthorizationLevel

 

 

' Else

 

 

Dim oAuthorizationLevels As New CRM.Core.ListItemFactory

 

 

Dim oList As ArrayList = Nothing

 

oList = oAuthorizationLevels.GetAuthorizationLevels(1033,

"CALC")

 

 

' oProductsArray = oListItemFactory.GetAuthorizationLevels(1033, cslist.SelectedValue)

 

 

' ddl.DataSource = oList

 

 

' ddl.DataTextField = "ItemKey"

 

 

' ddl.DataValueField = "ItemValue"

 

 

' ddl.DataBind()

 

 

' End If

 

 

'Else

 

 

 

'End If

 

 

Catch ex As Exception

 

HandleException(ex,

"BindDropdowns", "ExamManager.aspx.vb")

 

 

'Show error message.

 

ShowMessage(ex.Message)

 

End Try

 

 

End Sub

 

 

Private Function GetAllotmentById(ByVal item As GridDataItem) As CRM.Core.Allotment

 

 

Try

 

 

Dim AllotmentId As Integer = GetAllotmentId(item)

 

 

If AllotmentId > 0 Then

 

 

'Get the exam for that id.

 

 

Return GetAllotment(AllotmentId)

 

 

End If

 

 

Catch ex As Exception

 

HandleException(ex,

"GetAllotmentById", "PartnerAllotment.ascx.vb")

 

 

'Show error message.

 

ShowMessage(ex.Message)

 

End Try

 

 

Return New CRM.Core.Allotment

 

 

End Function

 

 

Private Function GetAllotmentId(ByVal item As GridDataItem) As Integer

 

 

Dim id As Integer = 0

 

 

Try

 

 

If item.IsInEditMode Then

 

 

Integer.TryParse(TryCast(item.FindControl("lblctViewableSNIDReadOnly"), Label).Text, id)

 

 

Else

 

 

Dim itemValue As String = item("ctViewableSNID").Text

 

 

Integer.TryParse(itemValue, id)

 

 

End If

 

 

 

Catch ex As Exception

 

 

'ignore error.

 

 

End Try

 

 

Return id

 

 

End Function

 

 

 

Private Function GetAllotmentIDNumber(ByVal item As GridDataItem) As String

 

 

Dim oProductReleaseID As String

 

oProductReleaseID =

CType(item.FindControl("lblctViewableSNID"), Label).Text

 

 

Return oProductReleaseID

 

 

End Function

 

 

 

Public Function GetAllotment(ByVal inID As Integer) As CRM.Core.Allotment

 

 

Try

 

 

Dim oAllotment As CRM.Core.Allotment() = GetPartnerAllotmentRuleByID(inID)

 

 

Return oAllotment(0)

 

 

Catch ex As Exception

 

 

Throw New CitrixException(ex.Message, "PACBasePage", "GetExam")

 

 

End Try

 

 

Return Nothing 'Some error occurred.

 

 

End Function

 

 

 

Public Function IsDataValid(ByVal inAllotment As CRM.Core.Allotment, ByVal inIsNew As Boolean, ByRef outErrorMessage As String) As Boolean

 

IsDataValid =

True

 

 

If Not IsNumeric(inAllotment.Quantity) Then

 

outErrorMessage = pErrorMsg_MissingProduct

 

Return False

 

 

End If

 

 

If Not IsNumeric(inAllotment.UserCount) Then

 

outErrorMessage = pErrorMsg_MissingUserCount

 

Return False

 

 

End If

 

 

If inAllotment.Product Is Nothing Then

 

outErrorMessage = pErrorMsg_MissingProduct

 

Return False

 

 

End If

 

 

If inAllotment.AuthorizationLevel Is Nothing Then

 

outErrorMessage = pErrorMsg_MissingAuthLevel

 

Return False

 

 

End If

 

 

'Check there is no duplicate. No similar record should exist in the database.

 

 

Dim existingRecords As Integer = 0

 

 

If Not inIsNew Then

 

existingRecords = 1

 

End If

 

 

End Function

 

#End

 

Region

 

 

 

End Class

 

0
Humberto
Top achievements
Rank 1
answered on 01 Dec 2010, 11:28 AM
sorry, i meant to say that i am using advanced databinding becausei am using NeedDataSource
0
Sergiu
Top achievements
Rank 2
answered on 20 May 2011, 09:19 PM
Not sure if you still need a reply to this question, I suggest you make sure that your Page Load event handler does not have any calls to Rebind or Databind your RadGrid instance... If you have any code in the Page Load event handler, make sure to wrap it around some sort of check for Postbacks... Hope this helps!
Tags
Grid
Asked by
Humberto
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Humberto
Top achievements
Rank 1
Sergiu
Top achievements
Rank 2
Share this question
or