title: Gridview, Edit UPdate
body: <p>I have output as below image</p>
  
  <p><a href="http://i.stack.imgur.com/kUtA7.jpg" rel="nofollow">Grid output</a></p>
  
  <p>This is my design page HTML source:</p>
  
  <pre><code>  &lt;form id="form1" runat="server"&gt;
          &lt;asp:ScriptManager ID="script1" runat="server"&gt;&lt;/asp:ScriptManager&gt;
      &lt;div&gt;
  
          &lt;table align="center" style="width:50%;"&gt;
              &lt;tr&gt;
                  &lt;td class="auto-style1"&gt;
                      &lt;asp:Label ID="Label1" runat="server" Text="Country Name" Font-Bold="True" ForeColor="Red"&gt;&lt;/asp:Label&gt;
                  &lt;/td&gt;
                  &lt;td&gt;
                      &lt;asp:TextBox ID="Text1" runat="server" Width="180px"&gt;&lt;/asp:TextBox&gt;
                  &lt;/td&gt;
                  &lt;td&gt;&amp;nbsp;&lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td class="auto-style1"&gt;
                      &lt;asp:Label ID="Label2" runat="server" Text="Country Notes" Font-Bold="True" ForeColor="Red"&gt;&lt;/asp:Label&gt;
                  &lt;/td&gt;
                  &lt;td&gt;
                      &lt;asp:TextBox ID="Text2" runat="server" Width="180px"&gt;&lt;/asp:TextBox&gt;
                  &lt;/td&gt;
                  &lt;td&gt;&amp;nbsp;&lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td&gt;
                      &lt;br /&gt;
                      &lt;asp:Button ID="Button1" runat="server" Text="Add" BackColor="#990000" ForeColor="White" OnClick="Button1_Click" /&gt;
                  &lt;/td&gt;
                  &lt;td&gt;&amp;nbsp;&lt;/td&gt;
                  &lt;td&gt;&amp;nbsp;&lt;/td&gt;
              &lt;/tr&gt;
  
          &lt;/table&gt;
  
          &lt;br /&gt;
          &lt;br /&gt;
  
      &lt;asp:UpdatePanel ID="UpdatePanel1" runat="server"&gt;
                 &lt;Triggers&gt;
  
                      &lt;asp:AsyncPostBackTrigger ControlID="GridView1" EventName="PageIndexChanging" /&gt;
  
                  &lt;/Triggers&gt;
          &lt;ContentTemplate&gt;
          &lt;asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" CellPadding="3" DataKeyNames="CountryID" DataSourceID="SqlDataSource1"  &gt;
              &lt;Columns&gt;
  
                  &lt;asp:CommandField ShowDeleteButton="True" ShowEditButton="True" /&gt;
  
                  &lt;asp:BoundField DataField="CountryID" HeaderText="CountryID" ReadOnly="True" SortExpression="CountryID" InsertVisible="False" /&gt;
                  &lt;asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" /&gt;
                  &lt;asp:BoundField DataField="CountryNotes" HeaderText="CountryNotes" SortExpression="CountryNotes" /&gt;
              &lt;/Columns&gt;
              &lt;FooterStyle BackColor="White" ForeColor="#000066" /&gt;
              &lt;HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" /&gt;
              &lt;PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Left" /&gt;
              &lt;RowStyle ForeColor="#000066" /&gt;
              &lt;SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" /&gt;
              &lt;SortedAscendingCellStyle BackColor="#F1F1F1" /&gt;
              &lt;SortedAscendingHeaderStyle BackColor="#007DBB" /&gt;
              &lt;SortedDescendingCellStyle BackColor="#CAC9C9" /&gt;
              &lt;SortedDescendingHeaderStyle BackColor="#00547E" /&gt;
          &lt;/asp:GridView&gt;
              &lt;/ContentTemplate&gt;
      &lt;/asp:UpdatePanel&gt;
          &lt;asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="&lt;%$ ConnectionStrings:ATSConnectionString %&gt;" DeleteCommand="DELETE FROM [country1] WHERE [CountryID] = @original_CountryID AND (([Name] = @original_Name) OR ([Name] IS NULL AND @original_Name IS NULL)) AND (([CountryNotes] = @original_CountryNotes) OR ([CountryNotes] IS NULL AND @original_CountryNotes IS NULL))" InsertCommand="INSERT INTO [country1] ([Name], [CountryNotes]) VALUES (@Name, @CountryNotes)" SelectCommand="SELECT * FROM [country1]" UpdateCommand="UPDATE [country1] SET [Name] = @Name, [CountryNotes] = @CountryNotes WHERE [CountryID] = @original_CountryID AND (([Name] = @original_Name) OR ([Name] IS NULL AND @original_Name IS NULL)) AND (([CountryNotes] = @original_CountryNotes) OR ([CountryNotes] IS NULL AND @original_CountryNotes IS NULL))" ConflictDetection="CompareAllValues" OldValuesParameterFormatString="original_{0}"&gt;
              &lt;DeleteParameters&gt;
                  &lt;asp:Parameter Name="original_CountryID" Type="Int32" /&gt;
                  &lt;asp:Parameter Name="original_Name" Type="String" /&gt;
                  &lt;asp:Parameter Name="original_CountryNotes" Type="String" /&gt;
              &lt;/DeleteParameters&gt;
              &lt;InsertParameters&gt;
                  &lt;asp:Parameter Name="Name" Type="String" /&gt;
                  &lt;asp:Parameter Name="CountryNotes" Type="String" /&gt;
              &lt;/InsertParameters&gt;
              &lt;UpdateParameters&gt;
                  &lt;asp:Parameter Name="Name" Type="String" /&gt;
                  &lt;asp:Parameter Name="CountryNotes" Type="String" /&gt;
                  &lt;asp:Parameter Name="original_CountryID" Type="Int32" /&gt;
                  &lt;asp:Parameter Name="original_Name" Type="String" /&gt;
                  &lt;asp:Parameter Name="original_CountryNotes" Type="String" /&gt;
              &lt;/UpdateParameters&gt;
          &lt;/asp:SqlDataSource&gt;
  
  &lt;/div&gt;
  </code></pre>
  
  <p>when i click edit button in any row of gridview,  i should get the values to the   textboxs which is in top of the page respectively and add button have to change as update button,  i should not get edit textbox on the rows of gridview,  could somebody help this problem</p>
  
  <p>this is my program</p>
  
  <pre><code>public partial class ACT : System.Web.UI.Page
  {
  
      SqlConnection con;
      SqlDataAdapter adapter;
      DataSet ds;
      SqlCommand cmd;
      public void Page_Load(object sender, EventArgs e)
      {
         if(!IsPostBack)
         {
             fillDataGrid();
         }
  
      }
      public void fillDataGrid()
      {
          con = new SqlConnection("Data Source=GARGI003-PC;Initial Catalog=ATS;Integrated Security=True");
          cmd = new SqlCommand("select * from country1", con);
          con.Open();
          adapter = new SqlDataAdapter(cmd);
          ds = new DataSet();
          adapter.Fill(ds, "country1");
  
          GridView1.DataBind();
          con.Close();
      }
      protected void Button1_Click(object sender, EventArgs e)
      {
          con = new SqlConnection("Data Source=GARGI003-PC;Initial Catalog=ATS;Integrated Security=True");
          cmd = new SqlCommand("insert into country1 (Name,CountryNotes) values(@Name, @CountryNotes)", con);
  
              cmd.Parameters.AddWithValue("@Name", Text1.Text);
              cmd.Parameters.AddWithValue("@CountryNotes", Text2.Text);
              con.Open();
              cmd.ExecuteNonQuery();
              con.Close();
  
              if (IsPostBack)
              {
                  Text1.Text = "";
                  Text2.Text = "";
                  fillDataGrid();                   
              }
  
      }
      protected void datagridview_PageIndexChanging(object sender, GridViewPageEventArgs e)
  
      {
          GridView1.PageIndex = e.NewPageIndex;
          fillDataGrid();
      }
  </code></pre>