Repeater中的imagebutton

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)
{
//事件
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值