• datalist控件内的查看,编辑


      private void bind()
      {
       this.DataList1.DataKeyField="EmployeeID";//在绑定的时候指定绑定的主键,方便后面更新,删除使用
      this.DataList1.DataSource=db.fill();
       this.DataList1.DataBind();
      }

      private void DataList1_ItemCommand(object source, System.Web.UI.WebControls.DataListCommandEventArgs e)
      {
       if(e.CommandName=="show")
       {
       this.DataList1.SelectedIndex=e.Item.ItemIndex;//选中的行索引
        this.bind();
       }
      }

      private void DataList1_CancelCommand(object source, System.Web.UI.WebControls.DataListCommandEventArgs e)
      {
       this.DataList1.EditItemIndex=-1;
       this.bind();
      }

      private void DataList1_EditCommand(object source, System.Web.UI.WebControls.DataListCommandEventArgs e)
      {
       this.DataList1.EditItemIndex=e.Item.ItemIndex;
       this.bind();
      }

      private void DataList1_UpdateCommand(object source, System.Web.UI.WebControls.DataListCommandEventArgs e)
      {//这里还有点问题,我没有更新到,懒得查,以后知道了再写
       string ID=this.DataList1.DataKeys[e.Item.ItemIndex].ToString();//查出选中行在数据库中的主键
       string city=((TextBox)e.Item.FindControl("txtcity")).Text;//查出修改文本框里的内容
       SqlConnection con=db.creatcon();
       SqlCommand cmd=new SqlCommand("update employees set city='"+city+"' where employeeID='"+ID+"'",con);
       con.Open();
       cmd.ExecuteNonQuery();
       this.DataList1.EditItemIndex=-1;//选中索引为-1,表示一个都没有选中
       this.bind();//重新绑定
      }

  • 相关阅读:
    C#入门(3)
    C#入门(2)
    C#入门(1)
    JNI工程搭建及编译
    Java-NestedClass(Interface).
    ConCurrent in Practice小记 (4)
    Java Annotation 注解
    Android使用ViewPager做轮播
    ConCurrent in Practice小记 (3)
    ConCurrent in Practice小记 (2)
  • 原文地址:https://www.cnblogs.com/thcjp/p/359763.html
Copyright © 2020-2023  润新知