title: How to delete row in gridview using rowdeleting event?
body: <p>This is my <code>.cs</code> code :</p>
  
  <pre><code>protected void Gridview1_RowDeleting(object sender, GridViewDeleteEventArgs e)
  {
   Gridview1.DeleteRow(e.RowIndex);
   Gridview1.DataBind();
  }
  </code></pre>
  
  <p>and this is <code>markup</code>,</p>
  
  <pre><code>&lt;asp:gridview ID="Gridview1" runat="server" ShowFooter="true" 
                                                  AutoGenerateColumns="false" OnRowDeleting="Gridview1_RowDeleting"&gt;
                      &lt;Columns&gt;
                      &lt;asp:BoundField DataField="RowNumber" HeaderText="Row Number" /&gt;
                      &lt;asp:TemplateField HeaderText="Column Name"&gt;
                          &lt;ItemTemplate&gt;
                              &lt;asp:TextBox ID="TextBox1" runat="server"&gt;&lt;/asp:TextBox&gt;
                          &lt;/ItemTemplate&gt;
                      &lt;/asp:TemplateField&gt;
  
                   &lt;%-- &lt;asp:TemplateField HeaderText="Header 2"&gt;
                          &lt;ItemTemplate&gt;
                              &lt;asp:TextBox ID="TextBox2" runat="server"&gt;&lt;/asp:TextBox&gt;
                          &lt;/ItemTemplate&gt;
                      &lt;/asp:TemplateField&gt;--%&gt;
                      &lt;asp:TemplateField HeaderText="Data Type"&gt;
                          &lt;ItemTemplate&gt;
                                &lt;asp:DropDownList ID="ddldatatype" runat="server"&gt;
                                &lt;asp:ListItem&gt;varchar&lt;/asp:ListItem&gt;
                                &lt;asp:ListItem&gt;int&lt;/asp:ListItem&gt;
                                &lt;asp:ListItem&gt;numeric&lt;/asp:ListItem&gt;
                                &lt;asp:ListItem&gt;uniqueidentifier&lt;/asp:ListItem&gt;
                                &lt;asp:ListItem&gt;char&lt;/asp:ListItem&gt;
                                &lt;/asp:DropDownList&gt;
                          &lt;/ItemTemplate&gt;
                          &lt;FooterStyle HorizontalAlign="Right" /&gt;
                          &lt;FooterTemplate&gt;
                          &lt;asp:Button ID="ButtonAdd" runat="server" Text="Add New Row" OnClick="ButtonAdd_Click"/&gt;
                           &lt;asp:Button ID="ButtonDel" runat="server" Text="Delete Row" OnClick="ButtonDel_Click" /&gt;
                           &lt;input type="hidden" runat="server" value="0" id="hiddencount" /&gt;
                          &lt;/FooterTemplate&gt;
                      &lt;/asp:TemplateField&gt;
                      &lt;asp:TemplateField&gt;
                          &lt;ItemTemplate&gt;
                              &lt;asp:LinkButton ID="lnkdelete" runat="server" CommandName="Delete" &gt;Delete&lt;/asp:LinkButton&gt;
                          &lt;/ItemTemplate&gt;
                      &lt;/asp:TemplateField&gt;
                      &lt;/Columns&gt;
              &lt;/asp:gridview&gt;
  </code></pre>
  
  <p>Please sugegest me. I have done this much.. but still not deleting row...</p>
  
  <pre><code> protected void Gridview1_RowDeleting(object sender, GridViewDeleteEventArgs e)
           {
  
  
               //Gridview1.DeleteRow((int)Gridview1.DataKeys[e.RowIndex].Value);
               //Gridview1.DeleteRow(e.RowIndex);
               //Gridview1.DataBind();
               foreach(DataRow dr in dt.Rows)
               {
                   dt.Rows.Remove(dr);
                   dt.Rows[e.RowIndex].Delete();
  
               }
               Gridview1.DeleteRow(e.RowIndex);
              // dt = (DataTable)Gridview1.DataSource;
               Gridview1.DataSource = dt;
               Gridview1.DataBind();
         }
  </code></pre>