asp.net-gridview

來源:互聯網
上載者:User

標籤:new   prot   localhost   綁定   tab   password   com   自己   text   

protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)        {            GridView1.EditIndex = -1;            Bindgrid();        }//編輯按鍵下的取消代碼。將EditIndex=-1,然後在綁定資料庫。        protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)        {             string id = GridView1.DataKeys[e.RowIndex][0].ToString();             DeleteGridView(id);             Bindgrid();        }// id = GridView1.DataKeys[e.RowIndex][0].ToString();獲得girdwiew中表的主鍵,作為刪除資料的標識。DeleteGirdView()為自己寫的刪除函數        protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)        {            GridView1.EditIndex = e.NewEditIndex;            Bindgrid();        }//擷取當前編輯狀態        protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)        {            string id = GridView1.DataKeys[e.RowIndex][0].ToString();            string uid = ((TextBox )GridView1.Rows[e.RowIndex].Cells[1].Controls[0]).Text;            string upassword = ((TextBox )GridView1.Rows[e.RowIndex].Cells[2].Controls[0]).Text;            string upower = ((TextBox)GridView1.Rows[e.RowIndex].Cells[3].Controls[0]).Text;            UpdataGridView(id, uid, upassword, upower);            GridView1.EditIndex = -1;            Bindgrid();        }//獲得GridView中選中行的各列資料,用UpdataGridView()更新資料        protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)        {            GridView1.PageIndex = e.NewPageIndex;            Bindgrid();        }//換頁的時候擷取當前編輯頁               public void UpdataGridView(string id,string uid,string upassword,string upower)        {           SqlConnection con=new SqlConnection ("server=localhost;database=YGXXXT;uid=sa;password=00");           string sql="update Users set ID=‘"+id+"‘,UID=‘"+uid+"‘,UPassword=‘"+upassword+"‘,UPower=‘"+upower+"‘";           SqlCommand cmd=new SqlCommand (sql,con );           con.Open ();           cmd.ExecuteNonQuery ();           con.Close();                   }//更新資料庫資料,注意sql語句裡的‘"+id+‘"不要弄錯格式~~~        public void DeleteGridView(string id)        {            SqlConnection con = new SqlConnection("server=localhost;database=YGXXXT;uid=sa;password=00");            string sql = "delete Users where ID=‘"+id +"‘";            SqlCommand cmd = new SqlCommand(sql, con);            con.Open();            cmd.ExecuteNonQuery();            con.Close();        }//刪除資料庫資料

 

asp.net-gridview

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.