+ -
当前位置:首页 → 问答吧 → repeater控件如何取得数据表中某一行的值

repeater控件如何取得数据表中某一行的值

时间:2011-08-22

来源:互联网

假设有一个aspx页面包含一个table,表格中的数据用一个repeater控件数据库绑定,aspx文件中代码如下:
<asp:Repeater ID="myRepeater" runat="server">
                <ItemTemplate>
            <tr>
                <td rowspan="2"><asp:Label runat="server"><%# Eval("c_name")%></asp:Label></td>      //c_name为数据表中的列名
            </tr>
                </ItemTemplate>
            </asp:Repeater>   
对应的CS文件代码:
  protected static string ConnAcc = ConfigurationSettings.AppSettings["ConnAcc"];//引导数据库连接
    protected void Page_Load(object sender, EventArgs e)
    {
        OleDbConnection myConn = new OleDbConnection(ConnAcc); //OleDb链接类的实例化
     myConn.Open();
        string course = "select * from [course]";
        OleDbDataAdapter cmd_course= new OleDbDataAdapter(course, myConn);
        DataSet ds = new DataSet();
        cmd_course.Fill(ds);
        Repeater1.DataSource = ds;
        Repeater1.DataBind();
    }
但这样就会在表格中显示所有c_name列中有数据的行,怎样实现只显示其中某一行的数据呢,假设数据表中还有一列c_id,怎样选择c_id=1的行呢?

作者: weifq24   发布时间: 2011-08-22

问题已解决,谢谢各位关注

作者: weifq24   发布时间: 2011-08-22