How do I manage multiple FOR loops in Multiview Navigation Event Handler - asp.net

Please bear with me a bit as I try to explain my problem.
I have multiple GridView controls, each with its own checkbox and textboxes.
User must either check the checkboxes or enter data into all textboxes.
If checkbox is not checked and textboxes within a particular gridview control is empty, when a user clicks the NEXT button of a multiview control, an error is raised.
The following code shows two FOR loops inside button click event of the NEXT navigation button.
The first Gridview1 FOR loop works great. If checkbox is not checked and the textboxes are empty, an alert message is displayed and user cannot navigate to next page.
If however, either the checkbox is checked or textboxes are filled with data, user can then successfully navigate to the next page.
The issue is with the second FOR loop for grvspouse gridview control.
If checkbox is not checked and textboxes are empty, the alert box is displayed with message that user must checkbox or enter data into textboxes. This is fine. However, the problem is that user is still taken to the next page.
Is there a way to handle multiple FOR loops inside BTN_NEXT navigation event handler?
Protected Sub btnNext_Click(ByVal sender As Object, ByVal e As EventArgs)
'If the message failed at some point, let the user know
For Each row As GridViewRow In Gridview1.Rows
Dim namesource As TextBox = TryCast(row.FindControl("txtsourcename"), TextBox)
Dim nmesource As String = namesource.Text
Dim addresssource As TextBox = TryCast(row.FindControl("txtsourceaddress"), TextBox)
Dim addrsource As String = addresssource.Text
Dim incomesource As TextBox = TryCast(row.FindControl("txtsourceincome"), TextBox)
Dim incmsource As String = incomesource.Text
Dim ckb As CheckBox = TryCast(row.FindControl("grid1Details"), CheckBox)
Dim checkb As Boolean = ckb.Checked
If checkb = False AndAlso nmesource = "" AndAlso addrsource = "" AndAlso incmsource = "" Then
ClientScript.RegisterStartupScript([GetType](), "Confirm", "jAlert('Please enter values on all textboxes or check the checkbox next to each textbox!');", True)
Else
myMultiView.ActiveViewIndex += 1
lblResult.Visible = True
End If
Next
For Each row As GridViewRow In grvspouse.Rows
Dim namespouse As TextBox = TryCast(row.FindControl("txtspousename"), TextBox)
Dim nmespouse As String = namespouse.Text
Dim addressspouse As TextBox = TryCast(row.FindControl("txtspouseaddress"), TextBox)
Dim addrspouse As String = addressspouse.Text
Dim incomespouse As TextBox = TryCast(row.FindControl("txtspouseincome"), TextBox)
Dim incmspouse As String = incomespouse.Text
Dim ckb2 As CheckBox = TryCast(row.FindControl("spouseDetails"), CheckBox)
Dim checkc As Boolean = ckb2.Checked
If checkc = False AndAlso nmespouse = "" AndAlso addrspouse = "" AndAlso incmspouse = "" Then
ClientScript.RegisterStartupScript([GetType](), "Confirm", "jAlert('Please enter values on all textboxes or check the checkbox next to each textbox!');", True)
Else
myMultiView.ActiveViewIndex += 1
lblResult.Visible = True
End If
Next
End Sub
[Edited]

You are facing this problem because you coded it that way....The easiest fix would be to create a STRING VARIABLE object and by each click,the program would check the VARIABLEfor a desired value and if the value matches then it'ld move to the next form.A complete example would look like this :
'Create a VARIABLE named HITCOUNT and keep the value empty at first.
Public class MyProject
Dim HITCOUNT as string = ""
If HITCOUNT = "" Then
For Each row As GridViewRow In Gridview1.Rows
Dim namesource As TextBox = TryCast(row.FindControl("txtsourcename"), TextBox)
Dim nmesource As String = namesource.Text
Dim addresssource As TextBox = TryCast(row.FindControl("txtsourceaddress"), TextBox)
Dim addrsource As String = addresssource.Text
Dim incomesource As TextBox = TryCast(row.FindControl("txtsourceincome"), TextBox)
Dim incmsource As String = incomesource.Text
Dim ckb As CheckBox = TryCast(row.FindControl("grid1Details"), CheckBox)
Dim checkb As Boolean = ckb.Checked
If checkb = False AndAlso nmesource = "" AndAlso addrsource = "" AndAlso incmsource = "" Then
ClientScript.RegisterStartupScript([GetType](), "Confirm", "jAlert('Please enter values on all textboxes or check the checkbox next to each textbox!');", True)
Else
myMultiView.ActiveViewIndex += 1
lblResult.Visible = True
End If
Next
HITCOUNT = "1" 'adding an integer value of 1(you can add anything)
End if
If HITCOUNT = "1" then
For Each row As GridViewRow In grvspouse.Rows
Dim namespouse As TextBox = TryCast(row.FindControl("txtspousename"), TextBox)
Dim nmespouse As String = namespouse.Text
Dim addressspouse As TextBox = TryCast(row.FindControl("txtspouseaddress"), TextBox)
Dim addrspouse As String = addressspouse.Text
Dim incomespouse As TextBox = TryCast(row.FindControl("txtspouseincome"), TextBox)
Dim incmspouse As String = incomespouse.Text
Dim ckb2 As CheckBox = TryCast(row.FindControl("spouseDetails"), CheckBox)
Dim checkc As Boolean = ckb2.Checked
If checkc = False AndAlso nmespouse = "" AndAlso addrspouse = "" AndAlso incmspouse = "" Then
ClientScript.RegisterStartupScript([GetType](), "Confirm", "jAlert('Please enter values on all textboxes or check the checkbox next to each textbox!');", True)
Else
myMultiView.ActiveViewIndex += 1
lblResult.Visible = True
End If
Next
HITCOUNT="2"
End if
'and move on and on
This is just one way and maybe the quickest one.There are many other ways to do so.If you don't wanna use this one, just comment and i'll post another solution

Related

Delete and Maintain Items on GridView

Sorry for the previous question I've posted. So here's my problem again, here's my code for the gridview.
`
If e.CommandName = "DeleteItem" Then
Dim gvItems As GridView = CType(sender, GridView)
Dim gvparent As GridViewRow = CType(gvItems.NamingContainer, GridViewRow)
'(gvparent.Cells(2).Text)
If gvItems.Rows.Count = 1 Then
lblPopup.Text = "There must be atleast one row."
mpeError.Show()
Exit Sub
End If
Program.oEquipmentLoan.sTransactionCode = gvparent.Cells(3).Text
'Dim gvItem As GridView = TryCast(gvitems.FindControl("gvItems"), GridView)
'For Each gvRow As GridViewRow In gvitems.Rows
' Dim chkItem As CheckBox = DirectCast(gvRow.FindControl("chkSelectItems"), CheckBox)
' If (chkItem.Checked) Then
' Program.oEquipmentLoan.iItemNumber = gvRow.Cells(2).Text
' oSQLEquipmentLoan.DeleteEquipmentLoanItem(Program.oEquipmentLoan)
' End If
'Next
'loadGVGetTransactionLog()
Dim icount As Integer = 0
For Each gvRow As GridViewRow In gvItems.Rows
Dim chkItem As CheckBox = DirectCast(gvRow.FindControl("chkSelectItems"), CheckBox)
If (chkItem.Checked) Then
icount += 1
End If
Next
If icount > 0 Then
For Each gvRow As GridViewRow In gvItems.Rows
Dim chkItem As CheckBox = DirectCast(gvRow.FindControl("chkSelectItems"), CheckBox)
If (chkItem.Checked) Then
Program.oEquipmentLoan.iItemNumber = gvRow.Cells(2).Text
oSQLEquipmentLoan.DeleteEquipmentLoanItem(Program.oEquipmentLoan)
End If
Next
Else
Dim gvr As GridViewRow = DirectCast(DirectCast(e.CommandSource, Control).NamingContainer, GridViewRow)
Dim Index As Integer = gvr.RowIndex
Dim gvRowSelected As GridViewRow = gvItems.Rows(Index)
Program.oEquipmentLoan.iItemNumber = gvRowSelected.Cells(2).Text
oSQLEquipmentLoan.DeleteEquipmentLoanItem(Program.oEquipmentLoan)
End If
End If
sIndex = gvTransactionLogViewer.PageIndex
blnCount = True
loadGVGetTransactionLog()
End Sub`
So, this code particularly deletes a selected row on a gridview. My problem is that whenever I delete an item, after it is deleted, I can't maintain to view the list.
Image given Below :
The photo shows on the before part is that when I'm selecting an item to delete. and on the after, when the item is deleted. And as you can see, what I need to maintain is the list of the updated items after I delete something and after it refreshes. Thanks! :)
on your .aspx page you need to do the partial postback to prevent the whole page postback.
you can achieve this using either asp.net ajax update panel "partial page rendering" or jquery.

dropdownlist does not show any values after postback

I've been battling with this issue for a couple of days now and would really appreciate if someone would shed some light for me.
I am populating a dropdownlist based on the selection from another dorpdownlist. As long as there is no postback happening, I see the list getting populated correctly but after a postback, my dropdownlist is empty.
At first, I was trying to manually set the Text property of the ddl but it kept giving me the following error:
System.ArgumentOutOfRangeException: ..ddl has a SelectedValue which is invalid because it does not exist in the list
Then I read somewhere that I need to set the DataValueField property instead so I did that which got rid of the error but now I see the empty dll after a postback.
The ViewStateMode for the ddl is set to Enabled.
The two ddls I'm referring to are defined in a Formview in my .aspx file as ddlCompanyBuyerNVListInsert and ddlCompanyNameListInsert(I'm listing the Insert mode only).
Based on the selections made in ddlCompanyBuyerNVList, I'm populating ddlCompanyNameList.
Here's the code behind for Page_Load and the functions that populate ddlCompanyNameList.
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
If NavHelper.User.UserName = "" Then
Dim UserIP As String
Dim UserLogin As String
Dim UserEmail As String
UserIP = HttpContext.Current.Request.UserHostAddress
UserLogin = HttpContext.Current.Session("Username")
UserEmail = HttpContext.Current.Session("Email")
GetUserInfo()
CurrentRFQ = Nothing
If NavHelper.RFQ.ID = -1 Then
formview_RFQ.ChangeMode(FormViewMode.Insert)
tabpanelCustomerParts.Visible = False
tabpanelDocuments.Visible = False
tabpanelReviews.Visible = False
tabpanelRFQReviewHistory.Visible = False
listview_CustomerParts.Dispose()
Else
formview_RFQ.ChangeMode(FormViewMode.Edit)
listview_ReviewContracts_Initial.EditIndex = 0
SessionHelper.CurrentObject = TAA.Library.RFQ.GetObject(NavHelper.RFQ.ID)
mRFQ = DirectCast(SessionHelper.CurrentObject, TAA.Library.RFQ)
Dim UserdeptTotal As Long
UserdeptTotal = HttpContext.Current.Session("DepartmentTotal")
If formview_RFQ.FindControl("ddlCompanyBuyerNVList") IsNot Nothing Then
Dim ddl As DropDownList = DirectCast(formview_RFQ.FindControl("ddlCompanyBuyerNVList"), DropDownList)
FillCompanyNameDropDownList(ddl)
End If
tabpanelCustomerParts.Visible = True
tabpanelDocuments.Visible = True
tabpanelReviews.Visible = True
tabpanelRFQReviewHistory.Visible = True
If NavHelper.RFQ.Copy = True Then
SetModifyCopy()
End If
End If
Else 'IsPostBack
datasource_BuyerNVList.Dispose()
datasource_RFQ.DataBind()
datasource_RFQNote.DataBind()
Dim ddl As DropDownList
If (formview_RFQ.CurrentMode = FormViewMode.Insert) Then
ddl = DirectCast(formview_RFQ.FindControl("ddlCompanyBuyerNVListInsert"), DropDownList)
ElseIf formview_RFQ.FindControl("ddlCompanyBuyerNVList") IsNot Nothing Then
ddl = DirectCast(formview_RFQ.FindControl("ddlCompanyBuyerNVList"), DropDownList)
End If
FillCompanyNameDropDownList(ddl)
End If
End If
End Sub
Protected Sub FillCompanyNameDropDownList(ddlCompanyBuyerNamesList As DropDownList)
Try
Using cn As New SqlClient.SqlConnection(DB.RFQconnection)
cn.Open()
Using cm As SqlClient.SqlCommand = cn.CreateCommand
cm.CommandType = CommandType.StoredProcedure
cm.CommandText = "GetCompanyNamesForThisBuyer"
cm.Parameters.AddWithValue("#BuyerName", (ddlCompanyBuyerNamesList.SelectedItem.Text))
Dim ddlCompanyNamesList As DropDownList
If (formview_RFQ.CurrentMode = FormViewMode.Insert) Then
ddlCompanyNamesList = DirectCast(formview_RFQ.FindControl("ddlCompanyNameListInsert"), DropDownList)
Else
ddlCompanyNamesList = DirectCast(formview_RFQ.FindControl("ddlCompanyNameList"), DropDownList)
End If
Using r As New SCF.Data.SafeDataReader(cm.ExecuteReader)
ddlCompanyNamesList.Items.Clear()
ddlCompanyNamesList.Items.Add(New ListItem("Select Company"))
While r.Read
Dim li As ListItem = New ListItem()
li.Value = SCF.Data.SafeData.SafeInteger(r("CompanyBuyerId"))
li.Text = SCF.Data.SafeData.SafeString(r("CompanyName"))
ddlCompanyNamesList.Items.Add(li)
End While
End Using
cm.Dispose()
cn.Close()
' if more than one entry found, clear the company info fields until a selection is made
If ddlCompanyNamesList.Items.Count > 2 Then 'because we've added a "Select Company" as the first item
ClearCompanyInfoFields() ' company fields are text boxes that get cleared here
ddlCompanyNamesList.SelectedIndex = 0
End If
ddlCompanyNamesList.Enabled = True
If ddlCompanyNamesList.Items.Count = 2 Then ' if only one entry found populate the compny info with that one entry's selection
ddlCompanyNamesList.SelectedIndex = 1
FillCompanyInfoFields(ddlCompanyNamesList)
ElseIf ddlCompanyNamesList.Items.Count = 0 Then ' if nothing found use the buyer list to populate company info fields
ddlCompanyNamesList.Items.Clear()
FillCompanyInfoFields(ddlCompanyBuyerNamesList)
ddlCompanyNamesList.Enabled = False
End If
End Using
End Using
Catch ex As System.Exception
SetErrorPanel("An error occured during FillCompanyNameDropDownList.")
Dim err As New HealthMonitoringCustomEvents.ErrorEvent("An error occured during FillCompanyNameDropDownList", Me, ex)
err.Raise()
End Try
End Sub
Protected Sub FillCompanyInfoFields(ddl As DropDownList)
Try
Dim buyerTitle As TextBox
Dim buyerEmail As TextBox
Dim buyerPhone As TextBox
Dim buyerExt As TextBox
Dim buyerMobile As TextBox
Dim buyerFax As TextBox
Dim CoAddr As TextBox
Dim CoCity As TextBox
Dim CoState As TextBox
Dim CoZip As TextBox
If (formview_RFQ.CurrentMode = FormViewMode.Insert) Then
buyerTitle = DirectCast(formview_RFQ.FindControl("txtBuyerTitleInsert"), TextBox)
buyerEmail = DirectCast(formview_RFQ.FindControl("txtBuyerEmailInsert"), TextBox)
buyerPhone = DirectCast(formview_RFQ.FindControl("txtBuyerPhoneNumberInsert"), TextBox)
buyerExt = DirectCast(formview_RFQ.FindControl("txtExtInsert"), TextBox)
buyerMobile = DirectCast(formview_RFQ.FindControl("txtBuyerMobileNumberInsert"), TextBox)
buyerFax = DirectCast(formview_RFQ.FindControl("txtBuyerFaxNumberInsert"), TextBox)
CoAddr = DirectCast(formview_RFQ.FindControl("txtCompanyAddressInsert"), TextBox)
CoCity = DirectCast(formview_RFQ.FindControl("txtCompanyCityInsert"), TextBox)
CoState = DirectCast(formview_RFQ.FindControl("txtCompanyStateCodeInsert"), TextBox)
CoZip = DirectCast(formview_RFQ.FindControl("txtCompanyZipCodeInsert"), TextBox)
Else
buyerTitle = DirectCast(formview_RFQ.FindControl("txtBuyerTitle"), TextBox)
buyerEmail = DirectCast(formview_RFQ.FindControl("txtBuyerEmail"), TextBox)
buyerPhone = DirectCast(formview_RFQ.FindControl("txtBuyerPhoneNumber"), TextBox)
buyerExt = DirectCast(formview_RFQ.FindControl("txtExt"), TextBox)
buyerMobile = DirectCast(formview_RFQ.FindControl("txtBuyerMobileNumber"), TextBox)
buyerFax = DirectCast(formview_RFQ.FindControl("txtBuyerFaxNumber"), TextBox)
CoAddr = DirectCast(formview_RFQ.FindControl("txtCompanyAddress"), TextBox)
CoCity = DirectCast(formview_RFQ.FindControl("txtCompanyCity"), TextBox)
CoState = DirectCast(formview_RFQ.FindControl("txtCompanyStateCode"), TextBox)
CoZip = DirectCast(formview_RFQ.FindControl("txtCompanyZipCode"), TextBox)
End If
Using cn As New SqlClient.SqlConnection(DB.RFQconnection)
cn.Open()
Using cm As SqlClient.SqlCommand = cn.CreateCommand
cm.CommandType = CommandType.StoredProcedure
cm.CommandText = "GetBuyerCompanyInfo"
cm.Parameters.AddWithValue("#companyBuyerId", (ddl.SelectedValue))
Using r As New SCF.Data.SafeDataReader(cm.ExecuteReader)
' populate company information fields in CurrentRFQ
While r.Read
CurrentRFQ.CompanyID = SCF.Data.SafeData.SafeString(r(0))
CurrentRFQ.CompanyBuyerId = SCF.Data.SafeData.SafeString(r(7))
ddl.DataValueField = SCF.Data.SafeData.SafeString(r(1))
CoAddr.Text = SCF.Data.SafeData.SafeString(r(2))
CoCity.Text = SCF.Data.SafeData.SafeString(r(4))
CoState.Text = SCF.Data.SafeData.SafeString(r(5))
CoZip.Text = SCF.Data.SafeData.SafeString(r(6))
buyerTitle.Text = SCF.Data.SafeData.SafeString(r(9))
buyerEmail.Text = SCF.Data.SafeData.SafeString(r(10))
buyerPhone.Text = SCF.Data.SafeData.SafeString(r(11))
buyerExt.Text = SCF.Data.SafeData.SafeString(r(12))
buyerMobile.Text = SCF.Data.SafeData.SafeString(r(13))
buyerFax.Text = SCF.Data.SafeData.SafeString(r(14))
End While
End Using
cm.Dispose()
cn.Close()
End Using
End Using
Catch ex As System.Exception
SetErrorPanel("An error occured during FillCompanyInfoFields.")
Dim err As New HealthMonitoringCustomEvents.ErrorEvent("An error occured during FillCompanyInfoFields", Me, ex)
err.Raise()
End Try
End Sub
And here's how the two ddls are defined in the .aspx file.
<td> <asp:DropDownList ID="ddlCompanyBuyerNVListInsert" runat="server"
AppendDataBoundItems="true" AutoPostBack="true" CssClass="Input"
DataSourceID="datasource_BuyerNVlist" DataTextField="Key" DataValueField="Value"
OnSelectedIndexChanged="ddlCompanyBuyerNVListInsert_SelectedIndexChanged"
ViewStateMode="Enabled" Width="205px"> <asp:ListItem Selected="True" Text="Select
Buyer" Value="0" /> </asp:DropDownList> </td> <td></td> <td class="style4"> Company:
</td> <td>
<asp:DropDownList ID="ddlCompanyNameListInsert" runat="server"
AppendDataBoundItems="True" AutoPostBack="True" CssClass="Input"onselectedindexchanged="ddlCompanyNameListInsert_SelectedIndexChanged"
ViewStateMode="Enabled" Enabled="False"> </asp:DropDownList> </td>
Thank you so much for your response.

while paging in asp.net how to save text box values in grid

hi what is my problem is in grid view after page loading i am entering some values in text box but after pressing the next page that page values are disappearing..
how can i save and retrieve the values into the grid view ..
i am able to save it in session but how can i past it into the currect page..
here is my code i am able to save it into the values but
after changing other page again entering into the same page how can i past the values into the corresponding page..
Protected Sub Gridview1_PageIndexChanging(ByVal sender As Object, ByVal e As GridViewPageEventArgs)
'Gridview1.PageIndex = e.NewPageIndex
'SetInitialRow()
Dim pageindex As Integer = Gridview1.PageIndex
Response.Write(Gridview1.PageIndex.ToString())
Dim d As Integer = Gridview1.PageCount
Dim texts As String() = New String(Gridview1.PageSize - 1) {}
Dim textBox As TextBox
Dim count As Integer = 0
For Each row As GridViewRow In Gridview1.Rows
textBox = DirectCast(row.FindControl("TextBox1"), TextBox)
If textBox IsNot Nothing Then
texts(count) = textBox.Text
Else
texts(count) = ""
End If
count += 1
Next
Session("one" + "pageindex") = texts
Gridview1.PageIndex= e.NewPageIndex
SetInitialRow()
'Dim sessionint As Integer = Session("page" + "pageindex")
'If Session("page" + "pageindex") IsNot Nothing Then
' Dim textBox1 As TextBox
' Dim texts1 As String() = DirectCast(Session("page" + "pageindex"), String())
' For i As Integer = 0 To Gridview1.Rows.Count - 1
' textBox1 = DirectCast(Gridview1.Rows(i).FindControl("textbox"), TextBox)
' textBox1.Text = texts(i)
' Next
'End If
End Sub
what is your datasource to bind to the gridview ?
These are the 2 ways that I have been doing...
Grab the whole data table and put it into ViewState("dataTable"). Do your filtering of rows and data from there.
Everytime you press 'Next Page', update the rows into the ViewState("dataTable").
Then rebind the gridview with the ViewState("dataTable").
Update the database directly when you press "Next Page".

Field Validation in Repeater Control

I have a question related to asp.net and vb.net. I have a repeater control that I bind some data to and allow users to update/change fields within certain text boxes. I added a validation control to trigger when the user doesn't enter a valid date or the text "TBD". On submit, I want to go through and highlight each field where its corresponding validator is not valid. This is my current code, but I am lost as to how to find the text box control.
Sub ValidateDateField(ByVal sender As Object, _
ByVal args As ServerValidateEventArgs)
'validate against three conditions - date, "TBD", and "N/A"
Dim dtValue = args.Value
If dtValue.ToUpper = "TBD" Or dtValue.ToUpper = "N/A" Then
args.IsValid = True
ElseIf IsDate(dtValue) Then
args.IsValid = True
Else
args.IsValid = False
Dim cont As WebControl = DirectCast(Page.FindControl(args.ToString), WebControl)
cont.BackColor = Drawing.Color.White
util.Client_Alert("Please Update Highlighted Fields")
End If
End Sub
I am completely lost as to how to get cont = textbox1row1 of my repeater control. Please advise. All examples I have seen so far directly state the control as in text1.BackColor =
So I figured out the answer. Sorry for the question. Don't know why I didn't think about it sooner. I found the naming container of the my custom val and then found the control based on its name in the repeater. in vb.net it was something like this:
Sub ValidateDateField(ByVal sender As Object, _
ByVal args As ServerValidateEventArgs)
'args holds value. validate against three conditions - date, "TBD", and "N/A"
Dim dtValue = args.Value
Dim cont As CustomValidator = sender
Dim myNC As Control = cont.NamingContainer
Dim strControl As String
strControl = cont.ControlToValidate
Dim txtbox As TextBox = _
DirectCast(myNC.FindControl(cont.ControlToValidate), TextBox)
If dtValue.ToUpper = "TBD" Or dtValue.ToUpper = "N/A" Or IsDate(dtValue) Then
args.IsValid = True
txtbox.BackColor = Drawing.Color.Empty
Else
args.IsValid = False
txtbox.BackColor = Drawing.Color.White
End If
End Sub

While creating a gridview programmatically, how do I evaluate the value of a column?

I am creating a gridview programmatically and I want to use the solution to this question: Programmatically access GridView columns and manipulate. In other words, I want to hide the hyperlinkfield and instead display a templatefield if the value of the "submitted" column in the row is 1. I'm listing employment applications and letting the user click "Load Application" if they have not yet submitted an application, or displaying "submitted" in plain text if they have already submitted it. I know how to do this if I create my gridview in the aspx file, but I don't know how to do this when I'm creating my gridview at runtime. Here's my code:
Public Sub getSavedApps(ByVal userID As Integer)
Dim ds As New DataSet
ds = clsData.sqlGetAllApps(userID)
If ds.Tables(0).Rows.Count > 0 Then
popAppSelect.Show()
'let user select which app they want to work on
Dim grdAppSelect As New GridView
'need to find out if this row has a value of 1 or 0 for submitted
Dim submitted As Boolean
'position column
Dim fieldPosition As New BoundField
fieldPosition.DataField = "positionDesired"
fieldPosition.HeaderText = "Position Desired"
If fieldPosition.DataField.ToString = "" Then
fieldPosition.DataFormatString = "<em>No position specified</em>"
End If
Dim colPosition As DataControlField = fieldPosition
'date column
Dim fieldDate As New BoundField
fieldDate.DataField = "dateStarted"
fieldDate.HeaderText = "Date Started"
Dim colDate As DataControlField = fieldDate
Dim strAppID(0) As String
strAppID(0) = "appID"
Dim colLoad As DataControlField
'submitted column
If submitted Then
Dim fieldLoad As New TemplateField
fieldLoad.ItemTemplate = New GridViewTemplate(DataControlRowType.DataRow, "submitted")
colLoad = fieldLoad
Else
Dim fieldLoad As New HyperLinkField
fieldLoad.Text = "<b>Load Application »</b>"
fieldLoad.DataTextFormatString = "{0}"
fieldLoad.DataNavigateUrlFields = strAppID
fieldLoad.DataNavigateUrlFormatString = "?load={0}"
colLoad = fieldLoad
End If
'add the columns to the gridview
With grdAppSelect
.ID = "grdAppSelect"
.CssClass = "grdAppSelect"
.CellPadding = 5
.BorderWidth = "0"
.HeaderStyle.HorizontalAlign = HorizontalAlign.Left
With .Columns
.Add(colPosition)
.Add(colDate)
.Add(colLoad)
End With
.AutoGenerateColumns = False
.DataSource = ds.Tables(0)
.DataBind()
End With
Dim lnkNew As New HyperLink
lnkNew.Text = "<b>Start New Application »</b>"
lnkNew.NavigateUrl = "?load="
Dim strClear As New LiteralControl
strClear.Text = "<br class='clearer' />"
'add the controls to the panel
pnlAppSelect.Controls.Add(grdAppSelect)
pnlAppSelect.Controls.Add(strClear)
'pnlAppSelect.Controls.Add(lnkNew)
Else
'should be apps there but couldn't find them
lblGeneralError.Text = "Could not find any previously started applications."
End If
End Sub
I found the solution. I needed to add an event handler when I created the gridview so that I could access the RowDataBound event and do the evaluation there. Here's the event handler code I used:
AddHandler grdAppSelect.RowDataBound, AddressOf grdAppSelect_RowDataBound
Then I just did my evaluation during RowDataBound like so:
Sub grdAppSelect_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
If e.Row.RowType = DataControlRowType.DataRow Then
Dim load As Control = e.Row.Controls(2)
Dim submitted As Control = e.Row.Controls(3)
Dim submittedText As String = e.Row.Cells(3).Text
If submittedText = "True" Then
load.Visible = False
End If
submitted.Visible = False
End If
End Sub

Resources