Data Binding ASP.Net Tutorial

You can use a ButtonField to represent a custom command or one of the standard edit commands.
<%@ Page Language="C#" %>
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

    protected void grdProductCategories_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        int index = Int32.Parse((string)e.CommandArgument);
        int id = (int)grdProductCategories.DataKeys[index].Values["Id"];
        int position = (int)grdProductCategories.DataKeys[index].Values["Position"];
        switch (e.CommandName)
        {
            case "Up":
               position--;
               break;
            case "Down":
               position++;
               break;
        }
        srcProductCategories.UpdateParameters["Id"].DefaultValue = id.ToString();
        srcProductCategories.UpdateParameters["Position"].DefaultValue = position.ToString();
        srcProductCategories.Update();
    }



    Show ButtonField


    
    

            id="grdProductCategories"
        DataSourceID="srcProductCategories"
        DataKeyNames="Id,Position"
        AutoGenerateColumns="false"
        OnRowCommand="grdProductCategories_RowCommand"
        Runat="server">
        
                    Text="Move Up"
            CommandName="Up" />
                    Text="Move Down"
            CommandName="Down" />
                    DataField="Position"
            HeaderText="Position" />
                    DataField="Name"
            HeaderText="Category Name" />
        

    
            id="srcProductCategories"
        ConnectionString="<%$ ConnectionStrings:Products %>"
        SelectCommand="SELECT Id, Name, Position FROM ProductCategories
            ORDER BY Position"
        UpdateCommand="UPDATE ProductCategories SET
            Position=@Position WHERE Id=@Id"
        Runat="server">
        
                    Name="Id" />
                    Name="Position" />
        

    
    

    


File: Web.config

  
             connectionString="Data Source=.\SQLEXPRESS;
         AttachDbFilename=|DataDirectory|MyDatabase.mdf;Integrated Security=True;User Instance=True" />