table模板里放个chart控件,然后放在repeater控件里,请问如何绑定chart?

protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
System.Web.UI.DataVisualization.Charting.Chart ct = (System.Web.UI.DataVisualization.Charting.Chart)e.Item.FindControl("Chart2");

        string connStr = "server=localhost;database=T_DB;uid=sa;pwd=123";
        SqlConnection myConn = new SqlConnection(connStr);
        string selStr = "select * from T_Motor1";
        SqlCommand myCmd = myConn.CreateCommand();
        myCmd.CommandText = selStr;
        myConn.Open();
        SqlDataReader sdr = myCmd.ExecuteReader(CommandBehavior.CloseConnection);
        ct.Series[0].Points.DataBindXY(sdr, "time", sdr, "speed");

        sdr.Close();
        myConn.Close();





    }

            <asp:Repeater ID="Repeater1" runat="server" OnItemDataBound="Repeater1_ItemDataBound">
   <ItemTemplate>   <table border="3" class="auto-style1">
        <tr>
            <td class="auto-style2">NO.<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
            </td>
            <td class="auto-style2">
                <asp:Chart ID="Chart2" runat="server">
                    <Series>
                        <asp:Series Name="Series1">
                        </asp:Series>
                    </Series>
                    <ChartAreas>
                        <asp:ChartArea Name="ChartArea1">
                        </asp:ChartArea>
                    </ChartAreas>
                </asp:Chart>
            </td>
        </tr>
    </table></ItemTemplate>  
    </asp:Repeater>

1个回答

可以用databinder

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐