hacresIT
asked on
Specify control within DataList Items
I am trying to specify a specific item/control inside the DataList control in my VB.NET codebehind.
I have a StartDateLabel and EndDateLabel. Both are databound to a SQL database. What I need to do is this;
If
StartDateLabel.Text = EndDateLabel.Text
Then
EndDateLabel.Visible = False
End If
Again, the problem is I don't know how to plug it in. What I need to know is how to specify the control within the Datalist Items. I have not worked with the Datalist control much (until recently) and could really use some help in this regard.
Thanks
I have a StartDateLabel and EndDateLabel. Both are databound to a SQL database. What I need to do is this;
If
StartDateLabel.Text = EndDateLabel.Text
Then
EndDateLabel.Visible = False
End If
Again, the problem is I don't know how to plug it in. What I need to know is how to specify the control within the Datalist Items. I have not worked with the Datalist control much (until recently) and could really use some help in this regard.
Thanks
ASKER
Ok, this is what I have so far:
-------------------------- ---------- ---------- ---------- -
Protected Sub DataList1_ItemDataBound1(B yVal sender As Object, ByVal e As System.Web.UI.WebControls. DataListIt emEventArg s) Handles DataList1.ItemDataBound
Dim StartDate As Label = CType(DataList1.FindContro l("StartDa teLabel"), Label)
Dim EndDate As Label = CType(DataList1.FindContro l("EndDate Label"), Label)
If StartDate.Text = EndDate.Text Then
EndDate.Visible = False
End If
End Sub
-------------------------- ---------- ------
I'm getting the following error:
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceExcept ion: Object reference not set to an instance of an object.
Source Error:
Line 7: Dim EndDate As Label = CType(DataList1.FindContro l("EndDate Label"), Label)
Line 8:
Line 9: If StartDate.Text = EndDate.Text Then
Line 10: EndDate.Visible = False
Line 11: End If
--------------------------
Protected Sub DataList1_ItemDataBound1(B
Dim StartDate As Label = CType(DataList1.FindContro
Dim EndDate As Label = CType(DataList1.FindContro
If StartDate.Text = EndDate.Text Then
EndDate.Visible = False
End If
End Sub
--------------------------
I'm getting the following error:
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceExcept
Source Error:
Line 7: Dim EndDate As Label = CType(DataList1.FindContro
Line 8:
Line 9: If StartDate.Text = EndDate.Text Then
Line 10: EndDate.Visible = False
Line 11: End If
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
within the itemdatabound event of the datalist, try something like:
Dim lbstart as label
dim lbend as label
lbstart = ctype(datalistname.findcon
lbend= ctype(datalistname.findcon
if lbstart.text = lbend.text then
lbend.visible = false
end if