Nugs
asked on
Hide Region if field is empty (Cont.) Multiple fields...
https://www.experts-exchange.com/questions/21381826/Hide-Region-if-field-is-empty-Cont-Multiple-fields.html
Hey there guys... I posted the above question in ASP... BlueDevilFan was kind enough to give me a function that will work if i can get it to work, but he was not knowledable in .Net the help me further, hense the post here...
Here was my question:
-----------------------
https://www.experts-exchange.com/questions/21372277/Hide-Region-if-field-is-empty.html
Ok guys... This is a continuation of my last post about this... I solved this problem of hiding a region of HTML if a field in the DB was blank... I now want to check multiple fields (5 to be exact) and if any of them has a value then visible=true and if all are blank visible=false...
Below is what i am doing to check only one field and hide or show depending on if the field holds a value... I wonder if you guys can help me modify this to check 5 fields or more...
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ------
...
Public Function DisplayVisible(ByVal fieldname As Object) As Boolean
If fieldname Is DBNull.Value Then
Return False
Else
Return True
End If
End Function
...
<asp:Label id="File1" Runat ="server" Visible ='<%#DisplayVisible(Contai ner.datait em("Fld_Fi le1"))%>'>
<a href="Upload/<%# DataBinder.Eval(Container. DataItem," FLD_File1" )%>"><img height="16" border="0" src="../images/attachment. gif" width="14"></a>
</asp:Label>
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ------
-------------------------- --
This is the function he gave me:
-------------------------- --
Public Function DisplayVisible() As Boolean
If (fieldname1 Is DBNull.Value) And (fieldname2 Is DBNull.Value) And (fieldname3 Is DBNull.Value) And (fieldname4 Is DBNull.Value) And (fieldname5 Is DBNull.Value) Then
Return False
Else
Return True
End If
End Function
-------------------------- --
I ended up modifying it slightly but get this error:
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- --------
Compiler Error Message: BC30451: Name 'Container' is not declared.
Source Error:
Line 78:
Line 79: Public Function DisplayVisible2() As Boolean
Line 80: If (Container.dataitem("Fld_F ile1") Is DBNull.Value) And (Container.dataitem("Fld_F ile2") Is DBNull.Value) And (Container.dataitem("Fld_F ile3") Is DBNull.Value) And (Container.dataitem("Fld_F ile4") Is DBNull.Value) And (Container.dataitem("Fld_F ile5") Is DBNull.Value) Then
Line 81: Return False
Line 82: Else
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------
Can you guys give me the right syntax for this?
Hey there guys... I posted the above question in ASP... BlueDevilFan was kind enough to give me a function that will work if i can get it to work, but he was not knowledable in .Net the help me further, hense the post here...
Here was my question:
-----------------------
https://www.experts-exchange.com/questions/21372277/Hide-Region-if-field-is-empty.html
Ok guys... This is a continuation of my last post about this... I solved this problem of hiding a region of HTML if a field in the DB was blank... I now want to check multiple fields (5 to be exact) and if any of them has a value then visible=true and if all are blank visible=false...
Below is what i am doing to check only one field and hide or show depending on if the field holds a value... I wonder if you guys can help me modify this to check 5 fields or more...
--------------------------
...
Public Function DisplayVisible(ByVal fieldname As Object) As Boolean
If fieldname Is DBNull.Value Then
Return False
Else
Return True
End If
End Function
...
<asp:Label id="File1" Runat ="server" Visible ='<%#DisplayVisible(Contai
<a href="Upload/<%# DataBinder.Eval(Container.
</asp:Label>
--------------------------
--------------------------
This is the function he gave me:
--------------------------
Public Function DisplayVisible() As Boolean
If (fieldname1 Is DBNull.Value) And (fieldname2 Is DBNull.Value) And (fieldname3 Is DBNull.Value) And (fieldname4 Is DBNull.Value) And (fieldname5 Is DBNull.Value) Then
Return False
Else
Return True
End If
End Function
--------------------------
I ended up modifying it slightly but get this error:
--------------------------
Compiler Error Message: BC30451: Name 'Container' is not declared.
Source Error:
Line 78:
Line 79: Public Function DisplayVisible2() As Boolean
Line 80: If (Container.dataitem("Fld_F
Line 81: Return False
Line 82: Else
--------------------------
Can you guys give me the right syntax for this?
ASKER
Well that sort of worked but i need it to return a true or false like this:
If fieldname Is DBNull.Value Then
Return False
Else
Return True
End If
----------
I tried doing sometihgn like this but that obviousley didn't work...
----------
Public Function DisplayVisible2(ByVal fieldname1 As Object, ByVal fieldname2 As Object, ByVal fieldname3 As Object, ByVal fieldname4 As Object, ByVal fieldname5 As Object) As Boolean
If (fieldname1 Is DBNull.Value) And (fieldname2 Is DBNull.Value) And (fieldname3 Is DBNull.Value) And (fieldname4 Is DBNull.Value) And (fieldname5 Is DBNull.Value)
Then
Return False
Else
Return True
End If
End Function
If fieldname Is DBNull.Value Then
Return False
Else
Return True
End If
----------
I tried doing sometihgn like this but that obviousley didn't work...
----------
Public Function DisplayVisible2(ByVal fieldname1 As Object, ByVal fieldname2 As Object, ByVal fieldname3 As Object, ByVal fieldname4 As Object, ByVal fieldname5 As Object) As Boolean
If (fieldname1 Is DBNull.Value) And (fieldname2 Is DBNull.Value) And (fieldname3 Is DBNull.Value) And (fieldname4 Is DBNull.Value) And (fieldname5 Is DBNull.Value)
Then
Return False
Else
Return True
End If
End Function
Let me see if I understand you correct.
You have 5 links, and if any of these is flled in the database you want to show all fife links right?
That would be:
<asp:Label id="Files" Runat ="server" Visible='<%#DisplayVisible (Container .dataitem( "Fld_File1 ") Or Container.dataitem("Fld_Fi le2") Or Container.dataitem("Fld_Fi le3") Or Container.dataitem("Fld_Fi le4") Or Container.dataitem("Fld_Fi le5"))%>'>
<a href="Upload/<%# DataBinder.Eval(Container. DataItem," FLD_File1" )%>"><img height="16" border="0" src="../images/attachment. gif" width="14"></a>
<a href="Upload/<%# DataBinder.Eval(Container. DataItem," FLD_File2" )%>"><img height="16" border="0" src="../images/attachment. gif" width="14"></a>
<a href="Upload/<%# DataBinder.Eval(Container. DataItem," FLD_File3" )%>"><img height="16" border="0" src="../images/attachment. gif" width="14"></a>
<a href="Upload/<%# DataBinder.Eval(Container. DataItem," FLD_File4" )%>"><img height="16" border="0" src="../images/attachment. gif" width="14"></a>
<a href="Upload/<%# DataBinder.Eval(Container. DataItem," FLD_File5" )%>"><img height="16" border="0" src="../images/attachment. gif" width="14"></a>
</asp:Label>
Or only show each label if an attachment is present. So something like:
<asp:Label id="File1" Runat ="server" Visible='<%#DisplayVisible (Container .dataitem( "Fld_File1 "))%>'>
<a href="Upload/<%# DataBinder.Eval(Container. DataItem," FLD_File1" )%>"><img height="16" border="0" src="../images/attachment. gif" width="14"></a>
</asp:Label>
<asp:Label id="File2" Runat ="server" Visible='<%#DisplayVisible (Container .dataitem( "Fld_File2 "))%>'>
<a href="Upload/<%# DataBinder.Eval(Container. DataItem," FLD_File2" )%>"><img height="16" border="0" src="../images/attachment. gif" width="14"></a>
</asp:Label>
<asp:Label id="File3" Runat ="server" Visible='<%#DisplayVisible (Container .dataitem( "Fld_File3 "))%>'>
<a href="Upload/<%# DataBinder.Eval(Container. DataItem," FLD_File3" )%>"><img height="16" border="0" src="../images/attachment. gif" width="14"></a>
</asp:Label>
<asp:Label id="File4" Runat ="server" Visible='<%#DisplayVisible (Container .dataitem( "Fld_File4 "))%>'>
<a href="Upload/<%# DataBinder.Eval(Container. DataItem," FLD_File4" )%>"><img height="16" border="0" src="../images/attachment. gif" width="14"></a>
</asp:Label>
<asp:Label id="File5" Runat ="server" Visible='<%#DisplayVisible (Container .dataitem( "Fld_File5 "))%>'>
<a href="Upload/<%# DataBinder.Eval(Container. DataItem," FLD_File5" )%>"><img height="16" border="0" src="../images/attachment. gif" width="14"></a>
</asp:Label>
Both would use the same function in the code-behind:
Public Function DisplayVisible(ByVal fieldname As Object) As Boolean
Return Not fieldname Is DBNull.Value
End Function
You have 5 links, and if any of these is flled in the database you want to show all fife links right?
That would be:
<asp:Label id="Files" Runat ="server" Visible='<%#DisplayVisible
<a href="Upload/<%# DataBinder.Eval(Container.
<a href="Upload/<%# DataBinder.Eval(Container.
<a href="Upload/<%# DataBinder.Eval(Container.
<a href="Upload/<%# DataBinder.Eval(Container.
<a href="Upload/<%# DataBinder.Eval(Container.
</asp:Label>
Or only show each label if an attachment is present. So something like:
<asp:Label id="File1" Runat ="server" Visible='<%#DisplayVisible
<a href="Upload/<%# DataBinder.Eval(Container.
</asp:Label>
<asp:Label id="File2" Runat ="server" Visible='<%#DisplayVisible
<a href="Upload/<%# DataBinder.Eval(Container.
</asp:Label>
<asp:Label id="File3" Runat ="server" Visible='<%#DisplayVisible
<a href="Upload/<%# DataBinder.Eval(Container.
</asp:Label>
<asp:Label id="File4" Runat ="server" Visible='<%#DisplayVisible
<a href="Upload/<%# DataBinder.Eval(Container.
</asp:Label>
<asp:Label id="File5" Runat ="server" Visible='<%#DisplayVisible
<a href="Upload/<%# DataBinder.Eval(Container.
</asp:Label>
Both would use the same function in the code-behind:
Public Function DisplayVisible(ByVal fieldname As Object) As Boolean
Return Not fieldname Is DBNull.Value
End Function
ASKER
uumm no, i have 5 fields in the DB ..... I have a lable.... I want to check all five fields in the DB and set the lables visible to 'true' if any of those fields hold a value...
I am doing this perfectly when checking only one field in the Db but now i want to check 5...
I am doing this perfectly when checking only one field in the Db but now i want to check 5...
That would be the final option I posted. Just to make sure you get the right one:
<asp:Label id="File1" Runat ="server" Visible='<%#DisplayVisible (Container .dataitem( "Fld_File1 "))%>'>
<a href="Upload/<%# DataBinder.Eval(Container. DataItem," FLD_File1" )%>"><img height="16" border="0" src="../images/attachment. gif" width="14"></a>
</asp:Label>
<asp:Label id="File2" Runat ="server" Visible='<%#DisplayVisible (Container .dataitem( "Fld_File2 "))%>'>
<a href="Upload/<%# DataBinder.Eval(Container. DataItem," FLD_File2" )%>"><img height="16" border="0" src="../images/attachment. gif" width="14"></a>
</asp:Label>
<asp:Label id="File3" Runat ="server" Visible='<%#DisplayVisible (Container .dataitem( "Fld_File3 "))%>'>
<a href="Upload/<%# DataBinder.Eval(Container. DataItem," FLD_File3" )%>"><img height="16" border="0" src="../images/attachment. gif" width="14"></a>
</asp:Label>
<asp:Label id="File4" Runat ="server" Visible='<%#DisplayVisible (Container .dataitem( "Fld_File4 "))%>'>
<a href="Upload/<%# DataBinder.Eval(Container. DataItem," FLD_File4" )%>"><img height="16" border="0" src="../images/attachment. gif" width="14"></a>
</asp:Label>
<asp:Label id="File5" Runat ="server" Visible='<%#DisplayVisible (Container .dataitem( "Fld_File5 "))%>'>
<a href="Upload/<%# DataBinder.Eval(Container. DataItem," FLD_File5" )%>"><img height="16" border="0" src="../images/attachment. gif" width="14"></a>
</asp:Label>
Both would use the same function in the code-behind:
Public Function DisplayVisible(ByVal fieldname As Object) As Boolean
Return Not fieldname Is DBNull.Value
End Function
<asp:Label id="File1" Runat ="server" Visible='<%#DisplayVisible
<a href="Upload/<%# DataBinder.Eval(Container.
</asp:Label>
<asp:Label id="File2" Runat ="server" Visible='<%#DisplayVisible
<a href="Upload/<%# DataBinder.Eval(Container.
</asp:Label>
<asp:Label id="File3" Runat ="server" Visible='<%#DisplayVisible
<a href="Upload/<%# DataBinder.Eval(Container.
</asp:Label>
<asp:Label id="File4" Runat ="server" Visible='<%#DisplayVisible
<a href="Upload/<%# DataBinder.Eval(Container.
</asp:Label>
<asp:Label id="File5" Runat ="server" Visible='<%#DisplayVisible
<a href="Upload/<%# DataBinder.Eval(Container.
</asp:Label>
Both would use the same function in the code-behind:
Public Function DisplayVisible(ByVal fieldname As Object) As Boolean
Return Not fieldname Is DBNull.Value
End Function
ASKER
Only one lable though....
one label, multiple files right? Try this:
<asp:Label id="File1" Runat ="server" Visible='<%#DisplayVisible (Container .dataitem( "Fld_File1 ") Or Container.dataitem("Fld_Fi le2") Or Container.dataitem("Fld_Fi le3") Or Container.dataitem("Fld_Fi le4") Or Container.dataitem("Fld_Fi le5"))%>'>
<span id="File1" RunAt="server" Visible='<%#DisplayVisible (Container .dataitem( "Fld_File1 ")%>'>
<a href="Upload/<%# DataBinder.Eval(Container. DataItem," FLD_File1" )%>"><img height="16" border="0" src="../images/attachment. gif" width="14"></a>
</span>
<span id="File2" RunAt="server" Visible='<%#DisplayVisible (Container .dataitem( "Fld_File2 ")%>'>
<a href="Upload/<%# DataBinder.Eval(Container. DataItem," FLD_File2" )%>"><img height="16" border="0" src="../images/attachment. gif" width="14"></a>
</span >
<span id="File3" RunAt="server" Visible='<%#DisplayVisible (Container .dataitem( "Fld_File3 ")%>'>
<a href="Upload/<%# DataBinder.Eval(Container. DataItem," FLD_File3" )%>"><img height="16" border="0" src="../images/attachment. gif" width="14"></a>
</span >
<span id="File4" RunAt="server" Visible='<%#DisplayVisible (Container .dataitem( "Fld_File4 ")%>'>
<a href="Upload/<%# DataBinder.Eval(Container. DataItem," FLD_File4" )%>"><img height="16" border="0" src="../images/attachment. gif" width="14"></a>
</span >
<span id="File5" RunAt="server" Visible='<%#DisplayVisible (Container .dataitem( "Fld_File5 ")%>'>
<a href="Upload/<%# DataBinder.Eval(Container. DataItem," FLD_File5" )%>"><img height="16" border="0" src="../images/attachment. gif" width="14"></a>
</span >
</asp:Label>
And in the codebehind:
Public Function DisplayVisible(ByVal fieldname As Object) As Boolean
Return Not fieldname Is DBNull.Value
End Function
<asp:Label id="File1" Runat ="server" Visible='<%#DisplayVisible
<span id="File1" RunAt="server" Visible='<%#DisplayVisible
<a href="Upload/<%# DataBinder.Eval(Container.
</span>
<span id="File2" RunAt="server" Visible='<%#DisplayVisible
<a href="Upload/<%# DataBinder.Eval(Container.
</span >
<span id="File3" RunAt="server" Visible='<%#DisplayVisible
<a href="Upload/<%# DataBinder.Eval(Container.
</span >
<span id="File4" RunAt="server" Visible='<%#DisplayVisible
<a href="Upload/<%# DataBinder.Eval(Container.
</span >
<span id="File5" RunAt="server" Visible='<%#DisplayVisible
<a href="Upload/<%# DataBinder.Eval(Container.
</span >
</asp:Label>
And in the codebehind:
Public Function DisplayVisible(ByVal fieldname As Object) As Boolean
Return Not fieldname Is DBNull.Value
End Function
made one tiny typo. The first span and the label have the same id. Just rename the label to FilesLabel or something to make it work.
ASKER
ToAoM, no here let me explain...
i have ONE image inside a lable. If any of the field (File1 through File5) in the database have a value then the image/ lable is displayed...
Somehting like this:
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- --------
<asp:Label id="File1" Runat ="server" Visible='<%#DisplayVisible 2(Containe r.dataitem ("Fld_File 1"),Contai ner.datait em("Fld_Fi le2"),Cont ainer.data item("Fld_ File3"),Co ntainer.da taitem("Fl d_File4"), Container. dataitem(" Fld_File5" ))%>'>
<img height="16" border="0" src="../images/attachment. gif" width="14">
</asp:Label>
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- --------
currently this is executing DisplayVisable2 which looks like this:
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- --------
Public Function DisplayVisible2(ByVal fieldname1 As Object, ByVal fieldname2 As Object, ByVal fieldname3 As Object, ByVal fieldname4 As Object, ByVal fieldname5 As Object) As Boolean
Return (fieldname1 Is DBNull.Value) And (fieldname2 Is DBNull.Value) And (fieldname3 Is DBNull.Value) And (fieldname4 Is DBNull.Value) And (fieldname5 Is DBNull.Value)
End Function
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- --------
So, one lable one image inside the lable checking 5 DB fields...
Nugs
i have ONE image inside a lable. If any of the field (File1 through File5) in the database have a value then the image/ lable is displayed...
Somehting like this:
--------------------------
<asp:Label id="File1" Runat ="server" Visible='<%#DisplayVisible
<img height="16" border="0" src="../images/attachment.
</asp:Label>
--------------------------
currently this is executing DisplayVisable2 which looks like this:
--------------------------
Public Function DisplayVisible2(ByVal fieldname1 As Object, ByVal fieldname2 As Object, ByVal fieldname3 As Object, ByVal fieldname4 As Object, ByVal fieldname5 As Object) As Boolean
Return (fieldname1 Is DBNull.Value) And (fieldname2 Is DBNull.Value) And (fieldname3 Is DBNull.Value) And (fieldname4 Is DBNull.Value) And (fieldname5 Is DBNull.Value)
End Function
--------------------------
So, one lable one image inside the lable checking 5 DB fields...
Nugs
<asp:Label id="File1" Runat ="server" Visible='<%#DisplayVisible (Container .dataitem( "Fld_File1 ") Or Container.dataitem("Fld_Fi le2") Or Container.dataitem("Fld_Fi le3") Or Container.dataitem("Fld_Fi le4") Or Container.dataitem("Fld_Fi le5"))%>'>
<img height="16" border="0" src="../images/attachment. gif" width="14">
</asp:Label>
Public Function DisplayVisible(ByRef field As Object) As Boolean
Return Not field Is DBNull.Value
End Function
<img height="16" border="0" src="../images/attachment.
</asp:Label>
Public Function DisplayVisible(ByRef field As Object) As Boolean
Return Not field Is DBNull.Value
End Function
ASKER
Exception Details: System.FormatException: Input string was not in a correct format.
Source Error:
Line 336: <td width="70%"><a href="ViewRecord.aspx?Fld_ id=<%# DataBinder.Eval(Container. DataItem," FLD_id")%> "><%# DataBinder.Eval(Container. DataItem," FLD_Title" )%></a></t d>
Line 337: <td width="10%" align="center" valign="middle" nowrap>
Line 338:<asp:Label id="File1" Runat ="server" Visible='<%#DisplayVisible 2(Containe r.dataitem ("Fld_File 1") Or Container.dataitem("Fld_Fi le2") Or Container.dataitem("Fld_Fi le3") Or Container.dataitem("Fld_Fi le4") Or Container.dataitem("Fld_Fi le5"))%>'>
Line 339:<img height="16" border="0" src="../images/attachment. gif" width="14">
Line 340:</asp:Label>
Source Error:
Line 336: <td width="70%"><a href="ViewRecord.aspx?Fld_
Line 337: <td width="10%" align="center" valign="middle" nowrap>
Line 338:<asp:Label id="File1" Runat ="server" Visible='<%#DisplayVisible
Line 339:<img height="16" border="0" src="../images/attachment.
Line 340:</asp:Label>
DisplayVisible2
shouldn't that be:
DisplayVisible
shouldn't that be:
DisplayVisible
ASKER
I changed the function name:
Public Function DisplayVisible2(ByRef field As Object) As Boolean
Return Not field Is DBNull.Value
End Function
Public Function DisplayVisible2(ByRef field As Object) As Boolean
Return Not field Is DBNull.Value
End Function
DisplayVisible2(Container. dataitem(" Fld_File1" ) Or Container.dataitem("Fld_Fi le2") Or Container.dataitem("Fld_Fi le3") Or Container.dataitem("Fld_Fi le4") Or Container.dataitem("Fld_Fi le5")).ToS tring()
It might need a ToString, but I'm a bit puzzled byu the VB.net syntax
It might need a ToString, but I'm a bit puzzled byu the VB.net syntax
ASKER
Exception Details: System.FormatException: Input string was not in a correct format.
could you pst the a little more details of the ASPX page you're working on, I'm trying to build a simple testcase here, but it's not working out as planned. Is the label inside a repeater or something?
ASKER
It's inside a datalist.... The one i am posting works for onefield in the Db but as you know i am trying to make it work to check multiple fields in the DB...
The Function:
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ----
Public Function DisplayVisible(ByVal fieldname As Object) As Boolean
If fieldname Is DBNull.Value Then
Return False
Else
Return True
End If
End Function
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ----
.....
.....
The Datalist:
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ----
<asp:DataList ID="DataList2"
runat="server"
Width="100%"
RepeatColumns="1"
RepeatDirection="Vertical"
RepeatLayout="Table">
<headertemplate>
<table width="100%" border="0" cellpadding="4" cellspacing="0">
<tr valign="top" bgcolor="#FFFFEC">
<td nowrap width="70%" bgcolor="#FFFFEC" class="Text style1">Title:</td>
<td nowrap width="10%" class="Text style1">Files:</td>
<td nowrap width="20%" class="Text style1">Date:</td>
</tr>
</table>
</headertemplate>
<itemtemplate>
<table width="100%" border="0" cellpadding="4" cellspacing="0">
<tr valign="bottom" class="TextSmall" onMouseOver="this.style.ba ckgroundCo lor='#C6D7 EB'" onMouseOut="this.style.bac kgroundCol or='#FFFFF F';">
<td width="70%"><a href="ViewRecord.aspx?Fld_ id=<%# DataBinder.Eval(Container. DataItem," FLD_id")%> "><%# DataBinder.Eval(Container. DataItem," FLD_Title" )%></a></t d>
<td width="10%" align="center" valign="middle" nowrap>
<asp:Label id="File1" Runat ="server" Visible ='<%#DisplayVisible(Contai ner.datait em("Fld_Fi le1"))%>'>
<img height="16" border="0" src="../images/attachment. gif" width="14">
</asp:Label>
</td>
<td width="20%" align="right" valign="middle" nowrap><%# DataBinder.Eval(Container. DataItem, "FLD_TimeStamp", "{0:MM/dd/yyyy}")%></td>
</tr>
</table>
</itemtemplate>
</asp:DataList>
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ----
The Function:
--------------------------
Public Function DisplayVisible(ByVal fieldname As Object) As Boolean
If fieldname Is DBNull.Value Then
Return False
Else
Return True
End If
End Function
--------------------------
.....
.....
The Datalist:
--------------------------
<asp:DataList ID="DataList2"
runat="server"
Width="100%"
RepeatColumns="1"
RepeatDirection="Vertical"
RepeatLayout="Table">
<headertemplate>
<table width="100%" border="0" cellpadding="4" cellspacing="0">
<tr valign="top" bgcolor="#FFFFEC">
<td nowrap width="70%" bgcolor="#FFFFEC" class="Text style1">Title:</td>
<td nowrap width="10%" class="Text style1">Files:</td>
<td nowrap width="20%" class="Text style1">Date:</td>
</tr>
</table>
</headertemplate>
<itemtemplate>
<table width="100%" border="0" cellpadding="4" cellspacing="0">
<tr valign="bottom" class="TextSmall" onMouseOver="this.style.ba
<td width="70%"><a href="ViewRecord.aspx?Fld_
<td width="10%" align="center" valign="middle" nowrap>
<asp:Label id="File1" Runat ="server" Visible ='<%#DisplayVisible(Contai
<img height="16" border="0" src="../images/attachment.
</asp:Label>
</td>
<td width="20%" align="right" valign="middle" nowrap><%# DataBinder.Eval(Container.
</tr>
</table>
</itemtemplate>
</asp:DataList>
--------------------------
ASKER
How about this.....
I write a function that takes the value of all 5 fields and places it inot a string... THEN i check the value of the string and if the string is Null THEN set a lable visible to FALSE...
I did something like this, i'm writing it to a lable just to test but i am having trouble pulling the value from the DB... What do i use instead of DataBinder.Eval(Container. DataItem," FLD_File3" ) to get the value from athe DB?
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---
Public Function SeekAnyFiles()
Dim strFiles As String
strFiles = DataBinder.Eval(Container. DataItem," FLD_File3" )
strFiles = strFiles + DataBinder.Eval(Container. DataItem," FLD_File3" )
lblTest.Text = strFiles
End Function
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---
Nugs
I write a function that takes the value of all 5 fields and places it inot a string... THEN i check the value of the string and if the string is Null THEN set a lable visible to FALSE...
I did something like this, i'm writing it to a lable just to test but i am having trouble pulling the value from the DB... What do i use instead of DataBinder.Eval(Container.
--------------------------
Public Function SeekAnyFiles()
Dim strFiles As String
strFiles = DataBinder.Eval(Container.
strFiles = strFiles + DataBinder.Eval(Container.
lblTest.Text = strFiles
End Function
--------------------------
Nugs
I've trid this with C# and VB.net now and in C# I would be uding the ItemDataBound event instead of inline these calls into the html itself.
It's a better place because of a couple of things. One is that it allows for compiler checking at compile time (whereas the html is only checked at runtime) and it's much cleaner:
I came up with the following C# event handler:
private void DataList1_ItemDataBound(ob ject sender, System.Web.UI.WebControls. DataListIt emEventArg s e)
{
if (e.Item.ItemType == ListItemType.Item)
{
if (
DataBinder.Eval(e.Item.Dat aItem, "Fld_File1") == DBNull.Value
&& DataBinder.Eval(e.Item.Dat aItem, "Fld_File2") == DBNull.Value
&& DataBinder.Eval(e.Item.Dat aItem, "Fld_File3") == DBNull.Value
&& DataBinder.Eval(e.Item.Dat aItem, "Fld_File4") == DBNull.Value
&& DataBinder.Eval(e.Item.Dat aItem, "Fld_File5") == DBNull.Value)
{
e.Item.FindControl("imgAtt achment"). Visible = false;
}
}
}
I guess VB would result in:
Private Sub DataList1_ItemDataboud(ByV al sender As System.Object, ByVal e As System.EventArgs) Handles DataList1.ItemDataboud
if (e.Item.ItemType = ListItemType.Item) then
if (
DataBinder.Eval(e.Item.Dat aItem, "Fld_File1") = DBNull.Value
And DataBinder.Eval(e.Item.Dat aItem, "Fld_File2") = DBNull.Value
And DataBinder.Eval(e.Item.Dat aItem, "Fld_File3") = DBNull.Value
And DataBinder.Eval(e.Item.Dat aItem, "Fld_File4") = DBNull.Value
And DataBinder.Eval(e.Item.Dat aItem, "Fld_File5") = DBNull.Value)
then
e.Item.FindControl("imgAtt achment"). Visible = false
end if
end if
End Sub
In this case you can just add visible="true" to the image. The same technique can be applied to the labels if you want to.
It's a better place because of a couple of things. One is that it allows for compiler checking at compile time (whereas the html is only checked at runtime) and it's much cleaner:
I came up with the following C# event handler:
private void DataList1_ItemDataBound(ob
{
if (e.Item.ItemType == ListItemType.Item)
{
if (
DataBinder.Eval(e.Item.Dat
&& DataBinder.Eval(e.Item.Dat
&& DataBinder.Eval(e.Item.Dat
&& DataBinder.Eval(e.Item.Dat
&& DataBinder.Eval(e.Item.Dat
{
e.Item.FindControl("imgAtt
}
}
}
I guess VB would result in:
Private Sub DataList1_ItemDataboud(ByV
if (e.Item.ItemType = ListItemType.Item) then
if (
DataBinder.Eval(e.Item.Dat
And DataBinder.Eval(e.Item.Dat
And DataBinder.Eval(e.Item.Dat
And DataBinder.Eval(e.Item.Dat
And DataBinder.Eval(e.Item.Dat
then
e.Item.FindControl("imgAtt
end if
end if
End Sub
In this case you can just add visible="true" to the image. The same technique can be applied to the labels if you want to.
ASKER
You said you did it in VB.Net.... Do you have that example?
That VB function I posted in my last post should do the job (it may contain some syntax errors though, I tried VB.net, but as I said before it clearly isn't language of choice).
ASKER
If you taling about:
<asp:Label id="File1" Runat ="server" Visible='<%#DisplayVisible (Container .dataitem( "Fld_File1 ") Or Container.dataitem("Fld_Fi le2") Or Container.dataitem("Fld_Fi le3") Or Container.dataitem("Fld_Fi le4") Or Container.dataitem("Fld_Fi le5"))%>'>
<img height="16" border="0" src="../images/attachment. gif" width="14">
</asp:Label>
Public Function DisplayVisible(ByRef field As Object) As Boolean
Return Not field Is DBNull.Value
End Function
Then no it doesn't work...
What about the idea of creating a string to check?
<asp:Label id="File1" Runat ="server" Visible='<%#DisplayVisible
<img height="16" border="0" src="../images/attachment.
</asp:Label>
Public Function DisplayVisible(ByRef field As Object) As Boolean
Return Not field Is DBNull.Value
End Function
Then no it doesn't work...
What about the idea of creating a string to check?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
<asp:Label id="File1" Runat ="server" Visible='<%#DisplayVisible
<a href="Upload/<%# DataBinder.Eval(Container.
</asp:Label>
Public Function DisplayVisible(ByVal fieldname1 As Object, ByVal fieldname2 As Object, ByVal fieldname3 As Object, ByVal fieldname4 As Object, ByVal fieldname5 As Object) As Boolean
Return (fieldname1 Is DBNull.Value) And (fieldname2 Is DBNull.Value) And (fieldname3 Is DBNull.Value) And (fieldname4 Is DBNull.Value) And (fieldname5 Is DBNull.Value)
End Function
NOTE: My primary language is C#, but I guess this should work.