三元运算符 在数据绑定中的使用

在使用 datalist 等控件绑定前台数据的时候,有时希望一行只显示定长字符,多出来的部分以省略号代替,我使用三元运算符来做:
None.gif < asp:DataList  id ="DataList1"  runat ="server"  RepeatColumns ="5"  Width ="616px" >
None.gif                            
< ItemTemplate >
None.gif                                
< table  border ="0"  cellpadding ="2"  cellspacing ="0"  align ="center"  width ="100%"  height ="100%" >
None.gif                                    
< tr >
None.gif                                        
< td  align ="center" >
None.gif                                            
< div  style ="height:10%;width:10%" >
ExpandedBlockStart.gifContractedBlock.gif                                                
<% dot.gif # DataBinder.Eval(Container.DataItem,"picexplanation").ToString().Length>10?DataBinder.Eval(Container.DataItem,"picexplanation").ToString().Substring(0,10)+"dot.gif":DataBinder.Eval(Container.DataItem,"picexplanation") %>
None.gif                                            
div >
None.gif                                        
td >
None.gif                                    
tr >
None.gif                                    
< tr >
None.gif                                        
< td  align ="center" >
None.gif                                            
< div  style ="height:90%;width:90%" >
None.gif                                                
< href ='viewphoto.aspx?imgurl=<%#  DataBinder.Eval(Container.DataItem,"primitivepic")% > ' target="_blank">
None.gif                                                    
< IMG  height =88  src ='../../../../../../upload_pic/userpic_small/<%#  DataBinder.Eval(Container.DataItem,"primitivepic")% > ' width=88 border=0> a > div >
None.gif                                        
td >
None.gif                                    
tr >
None.gif                                
table >
None.gif                            
ItemTemplate >
None.gif                        
asp:DataList >
用 Substring(x,x)定你需要显示的长度,而且表格高度都是固定的,这样在首页显示起来比较美观,不至于因为数据过长而导致变形,其实使用 div+css可以做的更好些,但是俺还没有学好那个东西,呵呵。大家有好的办法多多讨论,共同进步

转载于:https://www.cnblogs.com/devngm/archive/2007/04/11/708416.html

你可能感兴趣的:(三元运算符 在数据绑定中的使用)