Repeater中定义如下imagebutton :
<asp:imagebutton id="ImageButton_rpt" runat="server" CommandName="ms" CommandArgument='<%# DataBinder.Eval(Container.DataItem, "id")%>'></asp:imagebutton>
private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
{
SqlConnection conn=new SqlConnection();
String constr=ConfigurationSettings.AppSettings["sql"];
conn.ConnectionString=constr;
SqlCommand cmd=new SqlCommand();
cmd.CommandText="select * from companytable WHERE (sxid < 100)";
cmd.Connection=conn;
SqlDataAdapter da=new SqlDataAdapter();
da.SelectCommand=cmd;
DataSet ds=new DataSet();
da.Fill(ds); //创建分页类
PagedDataSource objPage=new PagedDataSource(); //设置数据源
objPage.DataSource=ds.Tables[0].DefaultView; //允许分页
objPage.AllowPaging=true; //设置每页显示的项数
objPage.PageSize=10; //定义变量用来保存当前索引
int CurPage;
if(Request.QueryString["Page"]!=null)
CurPage=Convert.ToInt32(Request.QueryString["Page"]);
else CurPage=1;
objPage.CurrentPageIndex=CurPage-1;
lblCurPage.Text="当前页:第"+CurPage.ToString()+"页";
if(!objPage.IsFirstPage)
LnkPrev.NavigateUrl=Request.CurrentExecutionFilePath+ "?leibie=A&Page=" +Convert.ToString(CurPage-1);
if(!objPage.IsLastPage)
LnkNext.NavigateUrl=Request.CurrentExecutionFilePath+ "?leibie=A&Page=" +Convert.ToString(CurPage+1);
Repeater1.DataSource=objPage;
Repeater1.DataBind();
da.Dispose();
conn.Close();
Repeater1_ItemCommand(null,null);
}
}
private void Repeater1_ItemCommand(object source, System.Web.UI.WebControls.RepeaterCommandEventArgs e)
{
System.Web.UI.WebControls.ImageButton ImageButton_rpt;
foreach(RepeaterItem rpt in Repeater1.Items)
{
ImageButton_rpt=(ImageButton)rpt.FindControl("ImageButton_rpt");
long i=Convert.ToInt64(ImageButton_rpt.CommandArgument);
if(i%2==0) //变换图片
{
ImageButton_rpt.ImageUrl="/mmjq/mmjq.files/fold_1.gif";
}
else
{
ImageButton_rpt.ImageUrl="/mmjq/mmjq.files/fold_2.gif";
}
}
if(!IsPostBack)
{;}
else
{
long ii=Convert.ToInt64(e.CommandArgument);
string strFlag1 = e.CommandName;
if(strFlag1=="ms")
{
mslx(ii);
}
}
}
private void mslx(long a)
{
//事件
}