Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Datalist - Find Control in Footer

Status
Not open for further replies.

mwa

Programmer
Joined
Jul 12, 2002
Messages
507
Location
US
I have a datalist that contains some textboxes in each item/alternatingitem. The users enters some data in the fields and clicks a "Save" button. In the code behind, I loop through the datalist items and validate the data that has been entered. If there is invalid data, I want to display a label that is located in the footer. How do I find that label and set visible = true? Here is what I have that does not work:

Code:
For Each i As DataListItem In DataList1.Items
     If i.ItemType = ListItemType.AlternatingItem Or i.ItemType = ListItemType.Item Then
     Dim fnd As TextBox = i.FindControl("txtItemFnd")
     Dim fnct As TextBox = i.FindControl("txtItemFnct")
     Dim obj As TextBox = i.FindControl("txtItemObj")
If SQLData.ValidateAccount(fnd.Text, fnct.Text, obj.Text) Then
     Save(Request.QueryString("id"), fnd.Text, fnct.Text, obj.Text, Session("myUserId"))
else
     'Find the Invalid label and make it visible (not working)
     For Each x As DataListItem In DataList1.Items
          If x.ItemType = ListItemType.Footer Then
               Dim lbl As Label = x.FindControl("InvalidMessage")
               lbl.Visible = True
          End If
     Next
end if
Next

Thanks in advance...

mwa
<><
 
Use the datalist's ItemDataBound event. In there you check the type of row that is being bound. If it is the footer, use .FindControl() to find the label and set it's visible property.
 
But, this function is getting called by a button click. the ItemDataBound event is not fired off.

mwa
<><
 
Exactly. Don't use the code you have, use the ItemDataBound event instead.
 
Feeling dense here... The data is already bound at the point when the button is clicked. The button causes a postback. If I rebind the data on the button click, won't I lose the values that were typed into the textboxes? And, make an extra call to the DB? Shouldn't I just loop trough the datalist items and validate what the user has keyed in to each items textboxes?

mwa
<><
 
Adding a screen shot...

screenprint.jpg


The values in text box are retrieved from the database. The user can change any of them and click Approve. The entered values are validated against another table. If they are not valid, the message should appear.

mwa
<><
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top