1. 程式人生 > 實用技巧 >.NET ------ Repeater 遍歷資料顯示在頁面上

.NET ------ Repeater 遍歷資料顯示在頁面上

做一個日誌檢視

藉助repeater 進行遍歷輸出資料

前面主要程式碼

    <table width="100%" cellpadding="4" cellspacing="0" class="tablecolor" id="divtable" style="white-space: nowrap">
       <tr bgcolor="#EEEEEE">
       <td  style="white-space: nowrap" align="center">學號</td>
       <td  style="white-space: nowrap
" align="center">姓名</td> <td style="white-space: nowrap" align="center">日誌</td> <td style="white-space: nowrap" align="center">登記人</td> </tr> <asp:Repeater ID="RepeaterStudentLog" runat="server"> <ItemTemplate> <tr bgcolor="
#FFFFFF" onMouseOver="this.bgColor='#FEFEFA'" onMouseOut="this.bgColor='#FFFFFF'" onclickX="javascript:document.getElementById('CheckData<%# Container.ItemIndex %>').checked=true;"> <td style="white-space: nowrap" align="center" <%# DataBinder.Eval(Container.DataItem,"RowColor
") %>><%# DataBinder.Eval(Container.DataItem, "StuMark") %></td> <td style="white-space: nowrap" align="center" <%# DataBinder.Eval(Container.DataItem,"RowColor") %>><%# DataBinder.Eval(Container.DataItem,"StuName") %>&nbsp;</td> <td style="white-space: nowrap" align="center" <%# DataBinder.Eval(Container.DataItem,"RowColor") %>><%# DataBinder.Eval(Container.DataItem, "LogContent") %></td> <td style="white-space: nowrap" align="center" <%# DataBinder.Eval(Container.DataItem,"RowColor") %>><%# DataBinder.Eval(Container.DataItem, "CreateUserID") %></td> </tr> </ItemTemplate> </asp:Repeater> </table>

後面將查出的集合複製給 repeater

    private void DataLoad()
    {
        bllStudentLog bllstudentlog = new bllStudentLog();
        List<StudentLog> mliststudentlog = bllstudentlog.GetListSelStudentLog3("*", base.EnterpriseGuid, " and StudentGuid = '" + _StuGuid + "'");
        this.RepeaterStudentLog.DataSource = mliststudentlog;
        this.RepeaterStudentLog.DataBind();

        //for (int i = 0; i <= mliststudentlog.Count - 1; i++)
        //{

        //    this.tbStuMark.Text = mliststudentlog[i].StuMark.ToString() + "&nbsp;";//學號
        //    this.tbStuName.Text = mliststudentlog[i].StuName.ToString() + "&nbsp;";//姓名
        //    this.tbLogContent.Text = mliststudentlog[i].LogContent.ToString() + "&nbsp;";//日誌內容         
        //    this.tbCreateUserID.Text = mliststudentlog[i].CreateUserID.ToString() + "&nbsp;";//操作員
        //}
        
               
    }