在一个Repeater里面,我要显示2张表的数据,应该怎么做?求指教<a href='Details.aspx?itemType=<%# Eval("itemType") %>&leather=<%# Eval("leather") %>' >Outside hand-stictched</a>
<%# Eval("itemType") %> 是itemtype表的
<%# Eval("leather") %> 是Leather表的请各位大侠指教!

解决方案 »

  1.   

    select a.itemType,b.leather from itemtype a,Leather b
      

  2.   


    可以把两张表连接起来 然后一起赋给Repeater 这样你就可以绑定了。。看看两张表有没有联系 如果有联系的话 直接连接类似select * from table a left join table b on a.ID=b.ID然后返回datatable  前提是两张表中有想等的字段 /// <summary>
            /// 执行有参的查询 返回DataTable
            /// </summary>
            /// <returns>返回DataTable</returns>
            public static DataTable ReturnDataTable(string cmdtext)
            {
                SqlConnection cn=new SqlConnection();
                cn.ConnectionString="数据库连接字符串";
                DataTable dt = new DataTable();
                SqlCommand cmd=new SqlCommand();
                cmd = new SqlCommand(cmdtext, cn);
                //类型
                cmd.CommandType = CommandType.Text;;
                SqlDataReader dr = null;
                //连接池 读完自动释放Connection
                using (dr = cmd.ExecuteReader(CommandBehavior.CloseConnection))
                {
                    //用委托填充DataTable
                    dt.Load(dr);
                }
                return dt;
            }传入你连接的SQL语句。。然后绑定就行了。