Hello, I've used the Formview-Control first time now because i was hoping to benefit from its paging- and FormViewMode capabilities. What is the recommended way of setting the datasource and the current row/record? I have a Gridview on the Page and i want to change the Formview Data after the Grid's SelectedIndexChanged-Event occured, but every promising property of the FormView is ReadOnly. I thought this must be a common requirement but didnt find much about it. Also i cant see the Pager although i have defined it: AllowPaging="true" PagerSettings-Position="Top" PagerSettings-Mode="NextPreviousFirstLast".
What i have is:
Private Sub GrdCharge_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles GrdCharge.SelectedIndexChanged
Dim idCharge As String = DirectCast(GrdCharge.SelectedRow.FindControl("LblIdCharge"), Label).Text
Me.FormView1.ChangeMode(FormViewMode.ReadOnly)
BindFormView(FormViewMode.ReadOnly, idCharge)
Me.UpdGrdCharge.Update()
End Sub
Private Sub BindFormView(ByVal mode As FormViewMode, ByVal strIdCharge As String)
Dim updPanelId As String = String.Empty
Select Case mode
Case FormViewMode.Insert
updPanelId = "UdpFormPanelAdd"
Case FormViewMode.ReadOnly, FormViewMode.Edit
Dim idCharge As Int32
If GetString(strIdCharge).Length = 0 OrElse Not Int32.TryParse(strIdCharge, idCharge) Then
Throw New ArgumentException("BindFormView needs a valid idCharge as parameter when in ReadOnly or Edit-Mode!")
Else
Dim drCharge As ERPModel.dsERP.ERP_ChargeRow = dsERP.ERP_Charge.FindByidCharge(idCharge) 'this is the current selected row
Me.FormView1.DataSource = dsERP.ERP_Charge 'this is a DataTable
'How to set the current Data Item shown in the FormView?? The following is all ReadOnly:
Me.FormView1.Row = drCharge 'Row is ReadOnly
Me.FormView1.SelectedValue = strIdCharge 'SelectedValue is ReadOnly
Me.FormView1.DataItem = drCharge 'DataItem is ReadOnly
Me.FormView1.DataBind()
End If
updPanelId = IIf(FormView1.CurrentMode = FormViewMode.ReadOnly, "UdpFormPanel", "UdpFormPanelEdit").ToString
End Select
Dim updPanel As UpdatePanel = DirectCast(FormView1.FindControl(updPanelId), UpdatePanel)
updPanel.Update()
End Sub
(C# Tag added because C#-sample code also welcome ;)) Regards
EDIT: I have changed the part in BindFormView to:
Select Case mode
Case FormViewMode.Insert
Case FormViewMode.ReadOnly, FormViewMode.Edit
Dim idCharge As Int32
If GetString(strIdCharge).Length = 0 OrElse Not Int32.TryParse(strIdCharge, idCharge) Then
Throw New ArgumentException("BindFormView needs a valid idCharge as parameter when in ReadOnly or Edit-Mode!")
Else
Me.FormView1.DataSource = dsERP.ERP_Charge.Select(dsERP.ERP_Charge.idChargeColumn.ColumnName & "=" & idCharge)
End If
End Select
Me.FormView1.DataKeyNames = New String() {dsERP.ERP_Charge.idChargeColumn.ColumnName}
Me.FormView1.DataBind()
That works for me. I still dont have a pager in FormView but i have achieved that the FormView Data changes according to the selectedindex in the GridView.
Thanks anyway.