如下所示:<a  title='<%# DataBinder.Eval(Container.DataItem,"InfoName")%>' 
href='/InfoShow.aspx?InfoID=<%# DataBinder.Eval(Container.DataItem,"InfoID") %>' target="_blank">
<span  style="CURSOR: hand">
<img src="images/news.jpg"></img>
<%# DataBinder.Eval(Container.DataItem,"InfoName") %>

</span>
</a>问题:
我通过sql查询最新10条记录显示,这个没有问题.
问题是我现在想在前台上述代码中将前面三条后面显示一个news图片,
就不知道该咋个弄了哈

解决方案 »

  1.   

    在行绑定事件中去判断当前行的索引,如果是0,1,2的话
    将itemtemplate中的一个<asp:literal id="newpic" runat="server" />的内容指定为newpic.text="<img src=newpic.gif>"
      

  2.   

    UI: <asp:DataList ID="DataList1" runat="server">
           
           <ItemTemplate>
            <%# eval("usr") %><asp:Literal ID="pic" runat="server" /><br />
           </ItemTemplate>
           
        </asp:DataList>CodebehindDim dsn As String = "provider=microsoft.jet.oledb.4.0;data source=" & Server.MapPath("~/app_data/db1.mdb")
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            If Not IsPostBack Then
                Call bind_datalist()
            End If
        End Sub    Function getdatasource() As DataTable        Dim conn As New OleDbConnection(dsn)
            Dim cmd As OleDbCommand = conn.CreateCommand
            cmd.CommandText = "select id,usr from usrinfo"
            Dim ad As New OleDbDataAdapter(cmd)
            Dim ds As New DataSet
            Dim tb As DataTable = Nothing
            Try
                ad.Fill(ds, "usrinfo")
                Return ds.Tables("usrinfo")
            Catch ex As Exception
                Throw ex
            Finally
                conn.Dispose()
                cmd.Dispose()
                ad.Dispose()
                ds.Dispose()
            End Try    End Function    Sub bind_datalist()
            DataList1.datasource = getdatasource()
            DataList1.databind()
        End Sub    Protected Sub DataList1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataListItemEventArgs) Handles DataList1.ItemDataBound        Select Case e.Item.ItemType
                Case ListItemType.Item, ListItemType.AlternatingItem                If e.Item.ItemIndex = 0 Or e.Item.ItemIndex = 1 Or e.Item.ItemIndex = 2 Then
                        CType(e.Item.FindControl("pic"), Literal).Text = "<img src=img/new.gif>"
                    End If        End Select    End Sub
      

  3.   

    楼上的方法可行,关键之处在于 页面处 用 Literal 控件
    codebehind 用 ItemDataBound 事件 来设定 前三条 的状态。
      

  4.   

    参看:
    http://blog.csdn.net/knight94/archive/2006/03/31/645987.aspx
      

  5.   

    我意思是能否在
    <%# DataBinder.Eval(Container.DataItem,"InfoName") %>
    后面直接判断datalist的index进行处理?
    如果能该咋个办?
    如果不能为什么呢??
      

  6.   

    你可以在ItemDataBound中赋itemtemplate中的某一label的值为itemindex值.
      

  7.   

    写个函数:: public string GetIfNew(string strDocNo, string strStaffNo)
            {
                string strReturn = "";
                SqlParameter[] pamNew = { 
                    new SqlParameter("@varDocNo",SqlDbType.VarChar,15,ParameterDirection.Input, true, 0, 0, null, DataRowVersion.Current,strDocNo),
                    new SqlParameter("@varStaffNo",SqlDbType.VarChar,8,ParameterDirection.Input, true, 0, 0, null, DataRowVersion.Current,strStaffNo) 
                };
                DataView dvNew = objDB.GetDataView("funGetBulletinVisitbyDocNo", pamNew);
                if (dvNew.Count > 0)
                {
                    if (dvNew.Table.Rows[0]["IfNewComment"].ToString().Trim() == "1")
                        strReturn = strReturn + "<img src='../images/comment.gif'>";
                }
                return strReturn;
            }
    前台调用::
    <%# GetIfNew(DataBinder.Eval(Container.DataItem, "DocNo").ToString())%>自己改一改就可以了