repeater 的编辑功能

很简单的实现.纪录下吧.编辑和编辑的时候对数据的检测.

 aspx:

 

 

function showerror(errordiv,errorstr)
{
document.getElementById(errordiv).innerText=errorstr;
}

function checkerror2(tb1,tb2,tb3)
{
var o1=document.getElementById(tb1);
var o2=document.getElementById(tb2);
var o3=document.getElementById(tb3);
var error="";
if(o1.value=="")error+="·discount can't empty! ";
if(o2.value=="")error+="·amountfrom can't empty! ";
if(o3.value=="")error+="·amountto can't empty! ";
if(error=="")return true;
else
{
showerror("error",error);
return false;
}
}

 

 


           
           
           
              
                    <%#Eval("dc_discount")%>%<%#Eval("dc_amoutfrom")%><%#Eval("dc_amoutto")%>
            

            
              
               
                   
                   
                   
                   
           
           

           

           

 

 

 

 

 cs:

 

protected void itemcmd(object sender, RepeaterCommandEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                string cmd = e.CommandName;
                int index = int.Parse(e.CommandArgument.ToString().Trim());

                switch (cmd)
                {
                    case "del":
                        {
                            lanvin.appcode.webhelp.checkaccess(me.gID, "ms_discount_del", me.isAdmin);

                            BLL.Tb_Discount blldis = new BLL.Tb_Discount();
                            blldis.Delete(index);
                            Function.JScript.AlertAndRedirect("success", "discount.aspx");
                            break;
                        }
                    case "edit":
                        {

                            lanvin.appcode.webhelp.checkaccess(me.gID, "ms_discount_update", me.isAdmin);
                            e.Item.FindControl("plview").Visible = false;
                            e.Item.FindControl("pledit").Visible = true;
                            break;
                        }
                    case "cancel":
                        {
                            e.Item.FindControl("plview").Visible = true;
                            e.Item.FindControl("pledit").Visible = false;
                            PageChange(this.LBPager1, new LBControl.LBPager.pagerarg(LBPager1.CurPage));
                            break;
                        }
                    case "save":
                        {

                            lanvin.appcode.webhelp.checkaccess(me.gID, "ms_discount_add", me.isAdmin);
                            try
                            {
                                BLL.Tb_Discount blldis = new BLL.Tb_Discount();
                                Model.Tb_Discount discount = blldis.GetModel(index);
                                string sdiscount = ((LBControl.LBTextBox)e.Item.FindControl("tbdiscount2")).Text;
                                string from = ((LBControl.LBTextBox)e.Item.FindControl("tbfrom2")).Text;
                                string to = ((LBControl.LBTextBox)e.Item.FindControl("tbto2")).Text;
                                discount.dc_AmoutFrom = int.Parse(from);
                                discount.dc_AmoutTo = int.Parse(to);
                                discount.dc_Discount = int.Parse(sdiscount);
                                blldis.Update(discount);
                                Function.JScript.AlertAndRedirect("success", "discount.aspx");
                            }
                            catch
                            {
                                Function.JScript.AlertAndRedirect("other error!", "discount.aspx");
                            }
                            break;
                        }
                    default:
                        {
                            break;
                        }
                }
            }
        }

 

 

 

protected void rpdb(object sender, RepeaterItemEventArgs e)
        {
            LBControl.LBTextBox tbdis = (LBControl.LBTextBox)e.Item.FindControl("tbdiscount2");
            LBControl.LBTextBox tbform = (LBControl.LBTextBox)e.Item.FindControl("tbfrom2");
            LBControl.LBTextBox tbto = (LBControl.LBTextBox)e.Item.FindControl("tbto2");

            ImageButton saveimg = (ImageButton)e.Item.FindControl("ImageButtonsave");
            saveimg.Attributes.Add("OnClick", "return checkerror2('" + tbdis.ClientID + "','" + tbform.ClientID + "','" + tbto.ClientID + "')");
        }

 

转载于:https://www.cnblogs.com/lsfv/archive/2010/02/26/1674150.html

你可能感兴趣的:(repeater 的编辑功能)