{"id":152,"date":"2012-11-07T13:09:46","date_gmt":"2012-11-07T13:09:46","guid":{"rendered":"http:\/\/www.mahmuttalhakoz.com\/blog\/?p=152"},"modified":"2012-11-07T13:11:52","modified_gmt":"2012-11-07T13:11:52","slug":"gridview-ile-edit-canceledit-update-delete-ve-select-kullanimi","status":"publish","type":"post","link":"https:\/\/www.mahmuttalhakoz.com\/blog\/index.php\/2012\/11\/07\/gridview-ile-edit-canceledit-update-delete-ve-select-kullanimi\/","title":{"rendered":"GridView ile Edit, CancelEdit, Update, Delete ve Select Kullanimi"},"content":{"rendered":"<p>Merhaba arkadaslar, GridView kullanimini kisaca inceleyecegiz. GridView&#8217;e veriyi cekmeden once &#8220;AutoGenerateColumns=&#8221;False&#8221;&#8221; olarak ayarliyoruz ve gosterilmesini istedigimiz sutunlari el ile ekliyoruz. (Resim 1, Resim 2)<br \/>\n<div id='gallery-1' class='gallery galleryid-152 gallery-columns-3 gallery-size-thumbnail'><figure class='gallery-item'>\n\t\t\t<div class='gallery-icon landscape'>\n\t\t\t\t<a href='https:\/\/www.mahmuttalhakoz.com\/blog\/wp-content\/uploads\/2012\/11\/mtk-grid-1.png'><img loading=\"lazy\" decoding=\"async\" width=\"150\" height=\"150\" src=\"https:\/\/www.mahmuttalhakoz.com\/blog\/wp-content\/uploads\/2012\/11\/mtk-grid-1-150x150.png\" class=\"attachment-thumbnail size-thumbnail\" alt=\"\" aria-describedby=\"gallery-1-153\" \/><\/a>\n\t\t\t<\/div>\n\t\t\t\t<figcaption class='wp-caption-text gallery-caption' id='gallery-1-153'>\n\t\t\t\tResim 1 &#8211; GridView\n\t\t\t\t<\/figcaption><\/figure><figure class='gallery-item'>\n\t\t\t<div class='gallery-icon landscape'>\n\t\t\t\t<a href='https:\/\/www.mahmuttalhakoz.com\/blog\/wp-content\/uploads\/2012\/11\/mtk-grid-2.png'><img loading=\"lazy\" decoding=\"async\" width=\"150\" height=\"150\" src=\"https:\/\/www.mahmuttalhakoz.com\/blog\/wp-content\/uploads\/2012\/11\/mtk-grid-2-150x150.png\" class=\"attachment-thumbnail size-thumbnail\" alt=\"\" \/><\/a>\n\t\t\t<\/div><\/figure>\n\t\t<\/div>\n<\/p>\n<p>Resim 2&#8217;de ekledigimiz &#8220;BoundField&#8221; nesnelerinin &#8220;DataField&#8221; degerlerine veritabanindaki tablomuzdan gosterilmesini istediginiz sutun adlarini giriyoruz. Degistirilmesini istemediginiz nesnelerin (Id gibi) &#8220;ReadOnly&#8221; ozelligini &#8220;True&#8221; yapmayi unutmayin.<\/p>\n<p>Simdi veritabanindan verilerimizi cekiyoruz. Baglanti cumlelerini yazmiyorum.<br \/>\n<code><br \/>\npublic void GetAllTest()<br \/>\n{<br \/>\nConnectionControl();<br \/>\nSqlDataAdapter Da = new SqlDataAdapter(\"SELECT * FROM AllTests\",myConnection);<br \/>\nDataSet Ds = new DataSet();<br \/>\nDa.Fill(Ds);<\/p>\n<p>GridView1.DataSource=Ds;<br \/>\nGridView1.DataBind();<br \/>\n}<br \/>\n<\/code><\/p>\n<p>GridView&#8217;e veriyi cektik.  GridView&#8217;de kullanacagimiz olaylar;<\/p>\n<ul>\n<li>onrowcancelingedit<\/li>\n<li>onrowdeleting<\/li>\n<li>onrowediting<\/li>\n<li>onrowupdating<\/li>\n<li>onselectedindexchanging<\/li>\n<\/ul>\n<p>Olaylar su sekilde kodlanacak;<br \/>\n<code><br \/>\n\/\/Edit Cancel<br \/>\n    protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)<br \/>\n    {<br \/>\n        GridView1.EditIndex = -1;<br \/>\n        GetAllTest();<br \/>\n    }<br \/>\n\/\/Delete<br \/>\n    protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)<br \/>\n    {<br \/>\n        ConnectionControl();<\/p>\n<p>        SqlCommand Cmd = new SqlCommand(\"DELETE FROM Users WHERE userID=@userId\", myConnection);<br \/>\n        Cmd.Parameters.Add(\"@userId\",SqlDbType.Int).Value = Convert.ToInt32(GridView1.Rows[e.RowIndex].Cells[3].Text);<br \/>\n        Cmd.ExecuteNonQuery();<\/p>\n<p>        GetAllTest();<br \/>\n    }<br \/>\n\/\/Edit<br \/>\n    protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)<br \/>\n    {<br \/>\n        GridView1.EditIndex = e.NewEditIndex;<br \/>\n        GetAllTest();<br \/>\n    }<br \/>\n\/\/Update<br \/>\n    protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)<br \/>\n    {<br \/>\n        TextBox adsoyad = new TextBox();<br \/>\n        adsoyad = (TextBox)GridView1.Rows[e.RowIndex].Cells[4].Controls[0];<br \/>\n        TextBox email = new TextBox();<br \/>\n        email = (TextBox)GridView1.Rows[e.RowIndex].Cells[5].Controls[0];<br \/>\n        CheckBox onay = new CheckBox();<br \/>\n        onay = (CheckBox)GridView1.Rows[e.RowIndex].Cells[6].Controls[0];<br \/>\n        bool durum=false;<br \/>\n        if (onay.Checked) durum = true;<br \/>\n        else durum = false;<\/p>\n<p>        ConnectionControl();<\/p>\n<p>        SqlCommand Cmd = new SqlCommand(\"UPDATE users SET adsoyad=@adsoyad,email=@email,status=@durum WHERE userID=@userId\", myConnection);<br \/>\n        Cmd.Parameters.Add(\"@adsoyad\",SqlDbType.NVarChar).Value = adsoyad.Text;<br \/>\n        Cmd.Parameters.Add(\"@email\",SqlDbType.NVarChar).Value = email.Text;<br \/>\n        Cmd.Parameters.Add(\"@durum\",SqlDbType.Bit).Value = durum;<br \/>\n        Cmd.Parameters.Add(\"@userId\",SqlDbType.Int).Value = Convert.ToInt32(GridView1.Rows[e.RowIndex].Cells[3].Text);<br \/>\n        cmd.ExecuteNonQuery();<\/p>\n<p>        DataSet Ds = new DataSet();<br \/>\n        SqlDataAdapterDa = new SqlDataAdapter(SELECT * FROM AllTests, myConnection);<br \/>\n        Da.Fill(Ds);<br \/>\n        GridView1.EditIndex = -1;<br \/>\n        GridView1.DataSource = Ds;<br \/>\n        GridView1.DataBind();<\/p>\n<p>        con.Close();<br \/>\n    }<br \/>\n<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Merhaba arkadaslar, GridView kullanimini kisaca inceleyecegiz. GridView&#8217;e veriyi cekmeden once<span class=\"more-dots\"><a href=\"https:\/\/www.mahmuttalhakoz.com\/blog\/index.php\/2012\/11\/07\/gridview-ile-edit-canceledit-update-delete-ve-select-kullanimi\/\">[ &#8230; ]<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[78,80,21,77,73,76,75,74,68,69,70,71,72,79],"class_list":["post-152","post","type-post","status-publish","format-standard","hentry","category-csharp","tag-canceledit","tag-delete-ve-select-kullanimi","tag-gridview","tag-gridview-ile-edit","tag-gridview1_rowcancelingedit","tag-gridview1_rowdeleting","tag-gridview1_rowediting","tag-gridview1_rowupdating","tag-onrowcancelingedit","tag-onrowdeleting","tag-onrowediting","tag-onrowupdating","tag-onselectedindexchanging","tag-update"],"_links":{"self":[{"href":"https:\/\/www.mahmuttalhakoz.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/152","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mahmuttalhakoz.com\/blog\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.mahmuttalhakoz.com\/blog\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.mahmuttalhakoz.com\/blog\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mahmuttalhakoz.com\/blog\/index.php\/wp-json\/wp\/v2\/comments?post=152"}],"version-history":[{"count":15,"href":"https:\/\/www.mahmuttalhakoz.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/152\/revisions"}],"predecessor-version":[{"id":170,"href":"https:\/\/www.mahmuttalhakoz.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/152\/revisions\/170"}],"wp:attachment":[{"href":"https:\/\/www.mahmuttalhakoz.com\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=152"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mahmuttalhakoz.com\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=152"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mahmuttalhakoz.com\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=152"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}