2012. 9. 13. 17:13

C# Repeater

* Repeater 를 코드 파일에서 값을 불러오는 방법입니다.


Default.aspx

<asp:Repeater ID="Repeater1" runat="server">
      <HeaderTemplate>
                    <table frame="hsides" >
                     <tr style="text-align:center; background-color:#33CCFF;">
                        <td  style="width:40px;">메세지 번호</td>
                        <td  style="width:80px;">IPADDRESS</td>
                        <td  style="width:550px;">SMS메세지</td>
                        <td  style="width:130px;">SMS 발송시간</td>
                    </tr>
        </HeaderTemplate>
            <ItemTemplate>
                    <tr>
                        <td align="center"width="80" bgcolor="#669999"><%# Eval("no")%></td>                       
                        <!--td><a href="/AdminMenu/Machine/MachineInfo.aspx?Mip=<%# Eval("IpAddr")%>" target="_blank"><%# Eval("IpAddr")%></a></td-->
                        <td align="center" width="150"><%# Eval("IpAddr")%></td>
                        <td align="left" width="700"> <%# Eval("Msg")%></td>
                        <td align="center" width="200"> <%# Eval("datetime")%></td>
                    </tr>
                    <tr><td></td></tr>     
            </ItemTemplate>
            <FooterTemplate>
                    <tr><td></td></tr>
                    <tr><td></td></tr>
                </table>       
            </FooterTemplate>
               
</asp:Repeater>




Default.aspx.cs


 private void Repeater_Data_Load()
    {
        using (MySqlConnection con = new MySqlConnection(ConfigurationManager.ConnectionStrings["MySQL"].ToString()))
        {
            MySqlCommand cmd = new MySqlCommand();
            cmd.Connection = con;

            if (con.State == ConnectionState.Closed)
            {
                con.Open();
            }

            //10분전 데이터 불러오기.
            //cmd.CommandText = "select no, ipaddr, msg, datetime from pushlog where datetime > date_format(date_add(now(),interval -10 minute), '%Y-%m-%d %H:%i:%s')";


            //30분전 데이터중 chargeNo 의 18번과 45번 불러오기
            //cmd.CommandText = "select * from pushlog where chargeNo in('18','45') and datetime > date_format(date_add(now(),interval -30 minute), '%Y-%m-%d %H:%i:%s')";


            //240분전 데이터중 chargeNo 의 18번 데이터만 불러오기
            cmd.CommandText = "select * from pushlog where chargeNo = '18' and datetime > date_format(date_add(now(),interval -240 minute), '%Y-%m-%d %H:%i:%s') order by no desc limit 30";

            //Repeater 테이블 담기.
            DataTable Repeater_Rows = new DataTable("Repeater_Rows");
            Repeater_Rows.Load(cmd.ExecuteReader());

            //DataReader 담기
            //MySqlDataReader DbReader = cmd.ExecuteReader();

            //Repeater에 저장.
            Repeater1.DataSource = Repeater_Rows;
            Repeater1.DataBind();
            Repeater1.Dispose();
            cmd.Dispose();

            //닫기.
            cmd.Parameters.Clear();
            con.Close();

        }
    }


Trackback 0 Comment 0