日期:2014-05-17  浏览次数:20514 次

listview点击进入编辑的错误,迷糊了
点击2次编辑按钮才能进入编辑状态,不知道为什么,那个大哥给看看,代码贴如下,经过测试,第一次点编辑ListView1.EditIndex 的值为0,第2次还是为0,但是第2次就进入编辑状态,不解,求答案。谢谢
C# code

public partial class HpUpdate : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                rptBind();
            }           
           
        }

       

        protected void ListView1_ItemCommand(object sender, ListViewCommandEventArgs e)
        {
            if (e.CommandName == "ImgbtnDelete")
            {
                HomePage model=new HomePage();
                model.id=Convert.ToInt32(e.CommandArgument);
                new HomePageBll().HPDelete(model);
                rptBind();
            }
            if (e.CommandName == "ImgbtnUpdate")
            {
               
                HomePage model = new HomePage();
                model.id = Convert.ToInt32(e.CommandArgument);
                model.T_Field = ((TextBox)ListView1.EditItem.FindControl("txtField")).Text;
                model.T_Order = ((TextBox)ListView1.EditItem.FindControl("txtOrder")).Text;
                new HomePageBll().HpUpdate(model);
                ListView1.EditIndex = -1;
                rptBind();
            }
            if (e.CommandName == "ImgbtnCancel")
            {
                ListView1.EditIndex = -1;
                rptBind();
            }
           
        }

       
        private void rptBind()
        {
            ListView1.DataSource = new HomePageBll().GetAll();
            ListView1.DataBind();
        }

        protected void ListView1_ItemEditing(object sender, ListViewEditEventArgs e)
        {
            ListView1.EditIndex = e.NewEditIndex;            
        }
       
      
    }



------解决方案--------------------
C# code

//应是这个
protected void ListView1_ItemEditing(object sender, ListViewEditEventArgs e)
        {
            ListView1.EditIndex = e.NewEditIndex;      
            rptBind();
        }