首先是一个控件绑定的Helper:
public class ListBinder
{
private List<Repeater> _controllist=new List<Repeater>();
public List<Repeater> Controllist
{
get { return _controllist; }
}
public void BindAll(IDataReader dr)
{
int length=this._controllist.Count;
for (int i = 0; i < length;i++ )
{
if (i == 0)
{
_controllist[i].DataSource = dr;
_controllist[i].DataBind();
}
else
{
if (dr.NextResult())
{
_controllist[i].DataSource = dr;
_controllist[i].DataBind();
}
}
}
}
}
string sql = "select top 5 * from [CaseShow] where [CategoryId]=9;select top 5 * from [CaseShow] where [CategoryId]=10;select top 5 * from [CaseShow] where [CategoryId]=11;select top 5 * from [CaseShow] where [CategoryId]=12";
using (IDbConnection con = AFrameWork.Data.DataFactory.GetConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString))
{
try
{
IDbCommand cmd = con.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = sql;
con.Open();
using (IDataReader dr = cmd.ExecuteReader())
{
ListBinder lb = new ListBinder();
lb.Controllist.Add(rpZhuanti);
lb.Controllist.Add(rpAd);
lb.Controllist.Add(rpHunli);
lb.Controllist.Add(rpPs);
lb.BindAll(dr);
}
}
catch
{
con.Close();
throw;
}