Conditional Statements using Repeater Control

thanhquanky

New Member
Does anyone know hoe to use conditionals with a Repeater. I have a few fields in my database that could possibly have a NULL value, and i dont want this displayed if this is the case...<BR><BR>Remember in classic ASP you could do ;<BR><BR><% if not rstitle("link") = NULL then %><BR>display link <BR><% else %><BR>dont display link <BR><% end if %><BR><BR>how do I do this with the Container.DataItem("link") command?<BR><BR>shreek25I ran into the same problem you had...what you have to do is make your own function. For instance, your example...<BR><BR> Public Function DisplayLink(ByVal link)<BR> If System.Convert.IsDBNull(link) Then<BR> DisplayLink=//display link code//<BR> Else<BR> DisplayLink=""<BR> End If<BR> End Function<BR><BR>you put that function in the code behind page, then in your repeater item template you would put...<BR><BR><%#DisplayLink(Container.DataItem("Link"))%><BR><BR>Hope that helps!<BR><BR>Tim<BR>Suppose I need to display a row of data in a table from the database. If there is null value then there should be no row displayed, if there is a row then a row would be displayed. Do you know how to achieve this<BR><BR>shreekIf you wanted to do what you are asking, why wouldn't you just modify the SQL that is generating the dataset to exclude rows that contain a NULL value in that certain column. Or if you don't want to change the SQL...you can create a dataview off of your dataset, filter your data, then bind your repeater to that dataview. For instance...<BR><BR> Dim myDataView As DataView<BR> myDataView = New DataView(YourDataSet.Tables("TABLE_NAME"))<BR> myDataView.RowFilter = "columnyoudonotwantnull IS NOT NULL"<BR> Repeater1.Databind = myDataView<BR><BR>I hope that was what you were looking for....OK. But if I have more than one column with NULL values then do i have to write the myDataView.RowFilter="Columniwantnull IS NOT NULL" more than once.<BR>Eg for two columns having null values<BR><BR>myDataView.RowFilter = "column1 IS NOT NULL"<BR>myDataView.RowFilter = "column2 IS NOT NULL"<BR><BR>Can I also know the SQL way to do it<BR>Thanx<BR>Below is the coldfusion code i need to convert to ASP.NET using repeaters..NE clues<BR>file1_type is a column in the database and so is file1_size <BR><BR><CFIF (file1_type NEQ '')><BR><TD NOWRAP><BR><FONT FACE="ARIAL,HELVETICA" SIZE="2">File Type: </FONT><FONT FACE="ARIAL,HELVETICA" SIZE="2"><B><BR><%#Container.DataItem("file1_type")%></B></FONT><BR></TD><BR></CFIF><BR><CFIF (file1_size NEQ '')><TD NOWRAP><FONT FACE="ARIAL,HELVETICA" SIZE="2">File Size: </FONT><BR><FONT FACE="ARIAL,HELVETICA" SIZE="2"><B><%#Container.DataItem("file1_size")%> Kb</B></FONT></TD></CFIF><BR></TR></TABLE><BR></TD></TR><BR></CFIF>I think the way to filter two columns would be:<BR>myDataView.RowFilter="column1 is NOT NULL AND column2 is NOT NULL"<BR>I don't know if the way you put it would work...but it might.<BR><BR>As for the SQL: <BR><BR>You would just add that the WHERE clause of your sql statement instead of using a filter...for example:<BR><BR>SELECT * FROM TABLE WHERE column1 IS NOT NULL AND column2 IS NOT NULL...etc...<BR><BR>TimThe SQL command dosent work <BR><BR>Below is the coldfusion code i need to convert to ASP.NET using repeaters..NE clues <BR>file1_type is a column in the database and so is file1_size <BR><BR><CFIF (file1_type NEQ '')> <BR><TD NOWRAP> <BR><FONT FACE="ARIAL,HELVETICA" SIZE="2">File Type: </FONT><FONT FACE="ARIAL,HELVETICA" SIZE="2"><B> <BR><%#Container.DataItem("file1_type")%></B></FONT> <BR></TD> <BR></CFIF> <BR><CFIF (file1_size NEQ '')><TD NOWRAP><FONT FACE="ARIAL,HELVETICA" SIZE="2">File Size: </FONT> <BR><FONT FACE="ARIAL,HELVETICA" SIZE="2"><B><%#Container.DataItem("file1_size")%> Kb</B></FONT></TD></CFIF> <BR></TR></TABLE> <BR></TD></TR> <BR></CFIF>Below is the coldfusion code i need to convert to ASP.NET using repeaters..NE clues <BR>file1_type is a column in the database and so is file1_size <BR><BR><CFIF (file1_type NEQ '')> <BR><TD NOWRAP> <BR><FONT FACE="ARIAL,HELVETICA" SIZE="2">File Type: </FONT><FONT FACE="ARIAL,HELVETICA" SIZE="2"><B> <BR><%#Container.DataItem("file1_type")%></B></FONT> <BR></TD> <BR></CFIF> <BR><CFIF (file1_size NEQ '')><TD NOWRAP><FONT FACE="ARIAL,HELVETICA" SIZE="2">File Size: </FONT> <BR><FONT FACE="ARIAL,HELVETICA" SIZE="2"><B><%#Container.DataItem("file1_size")%> Kb</B></FONT></TD></CFIF> <BR></TR></TABLE> <BR></TD></TR> <BR></CFIF>
 
Back
Top