repeater 多行多列+该背景色
cs:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class clinic_index : System.Web.UI.Page
{
protected int i = 0;
public string strsql, beijingse;
protected void Page_Load(object sender, EventArgs e)
{
strsql = "select top 64 business_id,left(business_name,10),left(business_company,10) from business where business_type like '%处方%' order by business_cishu desc";
SqlConnection con = new SqlConnection(ConfigurationSettings.AppSettings["Str_sql"]);
con.Open();
DataSet ds = new DataSet();
// 火暴招商1 rpt_hbzs
SqlDataAdapter sda_hbzs = new SqlDataAdapter(strsql, con);
sda_hbzs.Fill(ds,0,32,"hbzs");
rpt_hbzs.DataSource = ds.Tables["hbzs"];
rpt_hbzs.DataBind();
sda_hbzs.Fill(ds,32,32,"hbzs2");
rpt_hbzs2.DataSource = ds.Tables["hbzs2"];
rpt_hbzs2.DataBind();
sda_hbzs.Dispose();
con.Close();
con.Dispose();
}
protected void Repeater1_ItemDataBound(object sender,System.Web.UI.WebControls.RepeaterItemEventArgs e)
{
if (i % 4 == 0 && i > 0)
{
e.Item.Controls.Add(new System.Web.UI.LiteralControl("</tr><tr>"));
}
if (i == 0 || i==1 || i==2 || i ==3 || i ==8 || i ==9 || i ==10 || i ==11 || i ==16 || i ==17 || i ==18 || i ==19 || i ==24 || i ==25 || i ==26 || i ==27 )
{
beijingse = "#f7fbf7";
}
else
{
beijingse = "#e7f3ff";
}
i++;
}
}
aspx:
<asp:Repeater ID="rpt_hbzs" runat="server" OnItemDataBound="Repeater1_ItemDataBound">
<HeaderTemplate><table width="100%" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#92C9C6"><tr></HeaderTemplate>
<ItemTemplate>
<td height="22" bgcolor='<%#beijingse %>' width="25%">
[<%# DataBinder.Eval(Container.DataItem, "business_company")%>] <a href='<%#DataBinder.Eval(Container.DataItem,"business_id") %>' >
<%#DataBinder.Eval(Container.DataItem,"business_name") %>
</a>
</td>
</ItemTemplate>
<FooterTemplate> </tr></table></FooterTemplate>
</asp:Repeater>
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class clinic_index : System.Web.UI.Page
{
protected int i = 0;
public string strsql, beijingse;
protected void Page_Load(object sender, EventArgs e)
{
strsql = "select top 64 business_id,left(business_name,10),left(business_company,10) from business where business_type like '%处方%' order by business_cishu desc";
SqlConnection con = new SqlConnection(ConfigurationSettings.AppSettings["Str_sql"]);
con.Open();
DataSet ds = new DataSet();
// 火暴招商1 rpt_hbzs
SqlDataAdapter sda_hbzs = new SqlDataAdapter(strsql, con);
sda_hbzs.Fill(ds,0,32,"hbzs");
rpt_hbzs.DataSource = ds.Tables["hbzs"];
rpt_hbzs.DataBind();
sda_hbzs.Fill(ds,32,32,"hbzs2");
rpt_hbzs2.DataSource = ds.Tables["hbzs2"];
rpt_hbzs2.DataBind();
sda_hbzs.Dispose();
con.Close();
con.Dispose();
}
protected void Repeater1_ItemDataBound(object sender,System.Web.UI.WebControls.RepeaterItemEventArgs e)
{
if (i % 4 == 0 && i > 0)
{
e.Item.Controls.Add(new System.Web.UI.LiteralControl("</tr><tr>"));
}
if (i == 0 || i==1 || i==2 || i ==3 || i ==8 || i ==9 || i ==10 || i ==11 || i ==16 || i ==17 || i ==18 || i ==19 || i ==24 || i ==25 || i ==26 || i ==27 )
{
beijingse = "#f7fbf7";
}
else
{
beijingse = "#e7f3ff";
}
i++;
}
}
aspx:
<asp:Repeater ID="rpt_hbzs" runat="server" OnItemDataBound="Repeater1_ItemDataBound">
<HeaderTemplate><table width="100%" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#92C9C6"><tr></HeaderTemplate>
<ItemTemplate>
<td height="22" bgcolor='<%#beijingse %>' width="25%">
[<%# DataBinder.Eval(Container.DataItem, "business_company")%>] <a href='<%#DataBinder.Eval(Container.DataItem,"business_id") %>' >
<%#DataBinder.Eval(Container.DataItem,"business_name") %>
</a>
</td>
</ItemTemplate>
<FooterTemplate> </tr></table></FooterTemplate>
</asp:Repeater>