I'm trying to loop through every formview page in the ModeChanging event but it's not working right. Do you see anything wrong?
ProtectedSub fvApplicantComments_ModeChanging(ByVal
sender AsObject,
ByVal e
As System.Web.UI.WebControls.FormViewModeEventArgs)
Handles fvApplicantComments.ModeChanging
SelectCase e.NewMode
Case FormViewMode.Insert
Dim insertEmployeeIDLabel
As Label
For i
AsInteger = fvApplicantComments.PageCount
To 1
Step -1
That's right I'm looking for the employee_id in the item template. Trying to stop the load of the insert template if I already have a record for the user.
skujan57
0 Points
7 Posts
looping thru formview
Dec 23, 2012 02:05 AM|LINK
I'm trying to loop through every formview page in the ModeChanging event but it's not working right. Do you see anything wrong?
Protected Sub fvApplicantComments_ModeChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.FormViewModeEventArgs) Handles fvApplicantComments.ModeChanging
Select Case e.NewMode
Case FormViewMode.Insert
Dim insertEmployeeIDLabel As Label
For i As Integer = fvApplicantComments.PageCount To 1 Step -1
fvApplicantComments.PageIndex = i - 1
insertEmployeeIDLabel = fvApplicantComments.FindControl("employee_idLabel")
If Not insertEmployeeIDLabel Is Nothing Then
If insertEmployeeIDLabel.Text = Session("user_employee_id") Then e.Cancel = True
End If
Next
End Select
End Sub
oned_gk
All-Star
36192 Points
7370 Posts
Re: looping thru formview
Dec 23, 2012 02:19 AM|LINK
You dont need to loop all pages. Manipulate current page only, use page changed event or mode changed event.
Can you explaint what you want with that?
Suwandi - Non Graduate Programmer
skujan57
0 Points
7 Posts
Re: looping thru formview
Dec 23, 2012 02:53 AM|LINK
I'm trying to cancel the insert template if there already is a form for the user. I want each user to have only one form page.
oned_gk
All-Star
36192 Points
7370 Posts
Re: looping thru formview
Dec 23, 2012 03:08 AM|LINK
I dont understand why you find employeeid label inside insert template, because Insert template is blank form (not from db)
I think you will get employee id in itemtemplate or edititemtemplate only.
Suwandi - Non Graduate Programmer
skujan57
0 Points
7 Posts
Re: looping thru formview
Dec 23, 2012 03:15 AM|LINK
That's right I'm looking for the employee_id in the item template. Trying to stop the load of the insert template if I already have a record for the user.
oned_gk
All-Star
36192 Points
7370 Posts
Re: looping thru formview
Dec 23, 2012 06:02 AM|LINK
<asp:SqlDataSource ID="SqlDataSourceCheckUser" runat="server" ConnectionString="<%$ ConnectionStrings:TESTConnectionString %>" SelectCommand="SELECT * FROM [Yourtable] WHERE ([employee_id] = @employee_id)"> <SelectParameters> <asp:SessionParameter Name="employee_id" SessionField="user_employee_id" Type="String" /> </SelectParameters> </asp:SqlDataSource>DataTable dt = ((DataView)SqlDataSourceCheckUser.Select(DataSourceSelectArguments.Empty)).Table; if (dt.Rows.Count > 0) { //disable inserting here }Suwandi - Non Graduate Programmer
skujan57
0 Points
7 Posts
Re: looping thru formview
Dec 23, 2012 10:18 AM|LINK
Thanks, I took a similar approach:
Case FormViewMode.Insert
fvOnlyOne.DataBind()
Dim theOnlyOne As Label = fvOnlyOne.FindControl("theCountLabel")
If theOnlyOne.Text = "1" Then e.Cancel = True
oned_gk
All-Star
36192 Points
7370 Posts
Re: looping thru formview
Dec 23, 2012 10:47 AM|LINK
Suwandi - Non Graduate Programmer
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: looping thru formview
Dec 24, 2012 12:09 AM|LINK
Hello,
I come here and see the state of your issue has been marked as an answer, so I'll close your issue.
If you got anything feedback, please feel free to tell us by creating another new thread to continue,
Reguards!